列表提交git中的2个提交哈希 [英] List commits between 2 commit hashes in git

查看:94
本文介绍了列表提交git中的2个提交哈希的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这里有非常类似的问题,但他们没有解决我的问题。
也许有些东西我不明白。

这是fitnesse提交历史的一部分( https://github.com/unclebob/fitnesse/ ):

  * | | | | | | | | | | | | | | | fa86be8避免在大容量内存下使用CachingPage时可能出现的问题。 
| / / / / / / / / / / / / /
* | | | | | | | | | | | | | | 7b4a07a从barredijkstra / fitnesse_issue_250合并拉请求#256 $ b $ \\ * | | | | | | | | | | | | | | ecf5891修复操作系统特定异常消息的测试检查。
| * | | | | | | | | | | | | | | 082236e添加了导致异常的呈现。修复叔叔/ fitnesse#250
* | | | | | | | | | | | | | | | a92b37f合并来自amolenaar / fix / 243-hash-table-rendering的请求#243

我想要2个提交哈希之间的提交列表。在这种特殊情况下,我希望在 ecf5891 7b4a07a 之间进行提交,我期望得到的结果是: p>

  ecf5891 
7b4a07a

Si我一直在使用 git rev-list commit_hash_from_here ^ .. commit_hash_up_to_here ,它在线性历史记录中运行良好。然而,在这种情况下,我获得了更多的提交。



我已经试过了,它的工作方式和预期的一样:

  git log --since ='< date ecf5891>'--until ='< date 7b4a07a>'
pre>

(我手动搜索了这两个日期)。

一个可能的解决方案是获取2日期,只是做到这一点,但我认为应该有更好的方法。

编辑:
7b4a07a 父母 ecf5891 和 a92b37f 。到目前为止,如果我想要从 ecf5891 7b4a07a ,解决方案可以正常工作,但是如果我想从

$ $ $ $ $ $ $ $ $ p> 7b4a07a
ecf5891
082236e
a92b37f

但我没有得到 a92b37f

解决方案

Between 在涉及到git提交时,这是一个比较滑的概念。



上面显示的文本以及一段图表输出显示了为什么 <$ c从$ ..到 的$ c>产生的不仅仅是这两个提交: 部分是合并提交。



符号 A..B 实际上只是简写为 B ^ A 。也就是说,从 B> 开始的所有东西都是向后的,从 A 并向后工作。但是 是一个合并提交,因此从那里开始并向后工作的所有内容都使用父母

>

这里 7b4a07a 的第一个父母是 a92b37f 上面的[原始]片段,但我克隆了链接回购并找到它)。我们可以象征性地提及它,但我会在下面。 7b4a07a 的第二个父项是 ecf5891 ,您感兴趣的from部分。



当你要求:

  ecf5891 ^ .. 7b4a07a 

code>

表示:

  7b4a07a ^ ecf5891 ^ 


$ b $相同b

  7b4a07a ^ 082236e 

合并,然后从 082236e 返回修剪所有内容。您需要从> 7b4a07a ^ - 第一个父母以及后面的所有内容剪下所有内容:

  git rev-list 7b4a07a ^ ecf5891 ^ ^ 7b4a07a ^ 
git log --oneline 7b4a07a ^ ecf5891 ^ ^ 7b4a07a ^

一般来说,你必须弄清楚哪个后代线要剔除。

编辑:您可以坚持使用 A..B 符号,但您需要添加额外的排除。因此, jthill的回答也可以发挥作用,只要您将帽子移到前面即可。


$ b $如果我想从 a92b37f 7b4a07a code>):我们回到了之间作为一个光滑概念的问题。哪些提交是之间?从 a92b37f 7b4a07a 有一条直线,因为 a92b37f 是合并提交 7b4a07a 的两个父母之一。因此,通过较早的逻辑(直接提交祖先线,也许包容性),这只是这两个提交中的一个或两个提交。但是你说你需要两次提交,它们在任何祖先的意义上都不是与 a92b37f 有关。 为什么你想要这两个特定的提交?是什么使 082236e 有趣和 082236e ^ ,其父母无趣?

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/):

* | | | | | | | | | | | | | | | 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:

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.

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.

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
082236e
a92b37f

but I don't get a92b37f

解决方案

"Between" is a somewhat slippery notion, when it comes to git commits.

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.

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.

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.

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:

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 answer works too, once you move the hat to the front.


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. Why do you want those two particular commits? What makes 082236e "interesting" and 082236e^, its parent, "uninteresting"?

这篇关于列表提交git中的2个提交哈希的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆