有没有一种方法,除了实际检查父提交之外,还可以根据父克隆中的提交 ID 确定子模块的 SHA-1 提交 ID?我知道我可以找到当前与 git 子模块
关联的 SHA-1。
下面是一个示例:
- 我有一个带有单个子模块
foo
的克隆,该子模块在上个月已更改了多次。
- 我在父克隆中有一个几周前的标签,名为
released-1.2.3
。我想找出此标记提交的 foo
的关联 SHA-1 是什么。
- 我可以简单地查看
released-1.2.3
并使用 git submodule
来查看,但我想知道是否有办法做到这一点没有 影响工作树,因为我想编写它的脚本。
我想这样做是因为我想构建一个脚本来对父存储库中两次提交之间的子模块内的所有更改进行“比较” - 即“告诉我子模块中的哪些文件发生了更改 foo
在父级的这两个提交之间。”
Is there a way, short of actually checking out the parent commit, to determine a submodule's SHA-1 commit ID based on a commit ID in the parent clone? I know I can find the currently associated SHA-1 with git submodule
.
Here's an example:
- I have a clone with a single submodule
foo
that has changed several times in the last month.
- I have a tag in the parent clone that is a few weeks old called
released-1.2.3
. I want to find out what the associated SHA-1 of foo
was for this tagged commit.
- I could simply check out
released-1.2.3
and use git submodule
to see, but I'm wondering if there's a way to do this without affecting the working tree, as I want to script it.
I want to do this because I want to construct a script to do a 'diff' on all changes within a submodule between two commits within the parent repository - i.e. "tell me what files changed within the submodule foo
between these two commits in the parent."
发布评论
评论(5)
您可以使用
git-ls-tree
查看给定提交期间给定路径的 SHA-1 id 是什么:(我的第一个想法是 git showreleased-1.2.3 foo,但这失败了与“致命:坏对象”。)
由于您正在编写输出脚本,因此您可能只想获取 SHA-1 id 本身,例如:
另外:在围绕 git 编写脚本时,请尝试坚持 管道 命令,如手册中所述。它们具有更稳定的界面,而更熟悉的“瓷器”命令可能会以不兼容的方式发生变化。
You may use
git-ls-tree
to see what the SHA-1 id of a given path was during a given commit:(My first thought was
git show released-1.2.3 foo
, but that fails with "fatal: bad object".)Since you are scripting the output, you will probably want to get just the SHA-1 id by itself, e.g.:
Also: When writing scripts around git, try to stick to the plumbing commands, as described in the manual. They have a more stable interface, while the more familiar “porcelain” commands will possibly change in incompatible ways.
这对我有用:
也许在脚本中也很容易使用。
This one worked for me:
Perhaps also quite easy to use in script.
我确实找到了一个有希望的途径:
使用 --raw 选项,这确实会打印出与子模块的关联提交相对应的(缩写的)SHA-1 ID。不幸的是,输出非常冗长,需要在脚本中进行一些处理。
我真正需要的是一个 git 工具,在给定父提交 ID 的情况下,它可以为我提供该提交之前对子模块的最新更改。即,哪个子模块 SHA-1“git submodule update”将检查我是否要实际检查该父提交。
I did find one promising avenue:
With the --raw option, this does print out the (abbreviated) SHA-1 IDs corresponding to the submodule's associated commits. Unfortunately the output is very verbose and will take some work to process in a script.
What I really need is a git facility that, given a parent commit ID, gives me the latest change to a submodule prior to that commit. I.e. which submodule SHA-1 'git submodule update' would check out if I were to actually checkout that parent commit.
git Slave (gits) 可能就是你的答案。
http://gitslave.sourceforge.net/
但是你也可以用普通的 git 来做到这一点..它并不像简单的。
git slave (gits) might be your answer.
http://gitslave.sourceforge.net/
But you can also do this with plain git.. it's not as easy.
git
ls-tree
会完成这项工作。但有时您应该多次调用它或使用
-r
递归地显示子条目。例如,如果您有这样一个项目目录,并且您希望在父模块中使用
submodule_a
的提交 id 和标记名称。将为您提供目录
submodules
的树 ID,而不是提交 ID。看起来如下。只需向 ls-tree 提供树 id,您将获得每个子模块的实际提交 id。
你会得到这样的东西。
或者只是用来
检查所有条目树 id 或提交 id。
git
ls-tree
will do the job.But sometimes you should call it several times or use
-r
to show subentries recursively.For example, if you has such a project directory, and you want the commit id of
submodule_a
with an tag name in parent module.will give you the tree id of directory
submodules
, not commit id. It looks like as following.Just feed
ls-tree
with the tree id, and you will get the actual commit id of each submodule.You will get something like this.
Or just use
to check all entries tree id or commit id.