列出 git 中 2 个提交哈希之间的提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18679870/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
List commits between 2 commit hashes in git
提问by Nico
I know there has been very similar questions here, but they didn't solve my problem. Perhaps there's something I'm not understanding well.
我知道这里有非常相似的问题,但它们并没有解决我的问题。可能有什么我不太理解的地方。
This is a portion of the commit history of fitnesse (https://github.com/unclebob/fitnesse/):
这是fitnesse ( https://github.com/unclebob/fitnesse/)提交历史的一部分:
* | | | | | | | | | | | | | | | fa86be8 Avoid possible issue when using CachingPage under heavy memory load.
|/ / / / / / / / / / / / / / /
* | | | | | | | | | | | | | | 7b4a07a Merge pull request #256 from barredijkstra/fitnesse_issue_250
|\ \ \ \ \ \ \ \ \ \ \ \ \ \ \
| * | | | | | | | | | | | | | | ecf5891 Fixed test checking for OS specific exception message.
| * | | | | | | | | | | | | | | 082236e Added rendering of cause exceptions. Fix for unclebob/fitnesse#250
* | | | | | | | | | | | | | | | a92b37f Merge pull request #243 from amolenaar/fix/243-hash-table-rendering
I want the list of commits between 2 commit hashes. In this particular case, I want the commits between ecf5891
and 7b4a07a
, and I expect the result to be:
我想要 2 个提交哈希之间的提交列表。在这种特殊情况下,我希望在ecf5891
和之间进行提交7b4a07a
,并且我希望结果是:
ecf5891
7b4a07a
Si far I've been using git rev-list commit_hash_from_here^..commit_hash_up_to_here
and it has worked fine with linear history. However, in this case I get a lot more commits.
到目前为止,我一直在使用git rev-list commit_hash_from_here^..commit_hash_up_to_here
它,它在线性历史记录中运行良好。但是,在这种情况下,我得到了更多的提交。
I've tried this and it works just as expected:
我试过这个,它按预期工作:
git log --since='<date ecf5891>' --until='<date 7b4a07a>'
(I've manually searched for those 2 dates).
(我已经手动搜索了这两个日期)。
One possible solution is to get the 2 dates and just do that, but I think there should be a better way.
一种可能的解决方案是获取 2 个日期并执行此操作,但我认为应该有更好的方法。
Edit:
7b4a07a
parents are ecf5891
and a92b37f
. So far, the solutions work fine if I want to go from ecf5891
to 7b4a07a
, but if I want to go from a92b37f
to 7b4a07a
I want to get:
编辑:
7b4a07a
父母是ecf5891
和a92b37f
。到目前为止,如果我想从ecf5891
到7b4a07a
,解决方案工作正常,但如果我想从a92b37f
到 ,7b4a07a
我想得到:
7b4a07a
ecf5891
082236e
a92b37f
but I don't get a92b37f
但我不明白 a92b37f
回答by torek
"Between" is a somewhat slippery notion, when it comes to git commits.
谈到 git 提交时,“之间”是一个有点模糊的概念。
The text you show above, with a snippet of graph output, shows why from^..to
produces more than just those two commits: the to
part is a merge commit.
您在上面显示的文本以及一个图形输出片段,说明了为什么from^..to
产生的不仅仅是这两个提交:这to
部分是合并提交。
The notation A..B
is really just shorthand for B ^A
. That is, "everything starting from B
and working backwards, minus everything starting from A
and working backwards". But B
is a merge commit, so "everything starting there and working backwards" uses both parents.
该符号A..B
实际上只是 的简写B ^A
。也就是说,“一切从开始B
和向后工作,减去一切从开始A
和向后工作”。但是B
是合并提交,所以“一切从那里开始并向后工作”使用双亲。
Here the first parent of 7b4a07a
is a92b37f
(not in your [original] snippet above but I cloned the linked repo and found it). We can refer to it symbolically, though, and I will below. The second parent of 7b4a07a
is ecf5891
, the "from" part you're interested in.
这里的第一个父级7b4a07a
是a92b37f
(不在上面的 [原始] 片段中,但我克隆了链接的存储库并找到了它)。不过,我们可以象征性地引用它,我将在下文中提及。的第二个父项7b4a07a
是ecf5891
您感兴趣的“来自”部分。
When you ask for:
当您要求:
ecf5891^..7b4a07a
that means:
这意味着:
7b4a07a ^ecf5891^
which is the same as:
这与:
7b4a07a ^082236e
which gets you both parents of the merge, and then trims off everything from 082236e
back. You need to trim off everything from 7b4a07a^
—the first parent—and back as well:
这让您成为合并的父母,然后从082236e
后面修剪掉所有内容。您需要从7b4a07a^
第一个父级和后面修剪掉所有内容:
git rev-list 7b4a07a ^ecf5891^ ^7b4a07a^
git log --oneline 7b4a07a ^ecf5891^ ^7b4a07a^
In general, though, you have to figure out which descendent line(s) to chop-off.
但是,一般而言,您必须弄清楚要切断哪条后代线。
Edit: you can stick with the A..B
notation, but you do need to add the extra "exclude". So jthill's answerworks too, once you move the hat to the front.
编辑:您可以坚持使用A..B
符号,但您确实需要添加额外的“排除”。因此,一旦您将帽子移到前面,jthill 的答案也有效。
Re your edit ("if I want to go from a92b37f
to 7b4a07a
"): we're back to that issue of "between" being a slippery notion. Which commits are "between"? There's a direct line from a92b37f
to 7b4a07a
, because a92b37f
is one of the two parents of the merge commit 7b4a07a
. So by the earlier logic ("commits directly on an ancestral line", perhaps "inclusive") that would just be one, or maybe both, of those two commits. But you say you want two commits that are not, in any ancestral sense, related to a92b37f
at all. Whydo you want those two particular commits? What makes 082236e
"interesting" and 082236e^
, its parent, "uninteresting"?
重新编辑(“如果我想从a92b37f
到7b4a07a
”):我们又回到了“介于”这个概念上的问题。哪些提交是“介于”之间?从a92b37f
to有一条直线7b4a07a
,因为它a92b37f
是合并提交的两个父项之一7b4a07a
。因此,根据较早的逻辑(“直接在祖先线上提交”,也许是“包含”),这只是这两个提交中的一个,或者可能两者兼而有之。但是你说你想要两个在任何祖先意义上都没有任何关系的提交a92b37f
。 为什么你想要这两个特定的提交?是什么让082236e
“有趣”及082236e^
其父级“无趣”?
回答by aquavitae
I think that you`re looking for --ancestry-path, in your case:
我认为您正在寻找--ancestry-path,在您的情况下:
git rev-list --ancestry-path 7b4a07a..ecf5891
回答by Kasun Siyambalapitiya
First identify the relevant 2 commit hashes that you need for getting the list of commit hashes in between them by using
首先确定您需要使用的相关 2 个提交哈希来获取它们之间的提交哈希列表
git log --oneline
Then you can pick the relevant two commit hashes and find the commit hashes in between them by using
然后你可以选择相关的两个提交哈希,并通过使用找到它们之间的提交哈希
git log <commit hash 1> <commit hash 2> --oneline | cut -d " " -f 1
回答by jthill
Add ^7b4a07a~ to also exclude everything reachable from the merge's first parent. You're only excluding what's reachable from its second parent.
添加 ^7b4a07a~ 以排除可从合并的第一个父级访问的所有内容。您只是排除了可以从其第二个父级访问的内容。