从一个分支被分支到当前分支之后,最好的方法是什么?目前我的解决方案是:
git log $(git merge-base HEAD branch)..branch
git-diff的文档表明git diff A…B等价于git diff $(git-merge-base A B) B。另一方面,git-rev-parse的文档表明r1…R2被定义为r1 R2 -而不是$(git merge-base -all r1 R2)。
为什么这些不同呢?注意git diff HEAD…分支给了我想要的差异,但相应的git日志命令给了我比我想要的更多。
在图片中,假设:
x---y---z---branch
/
---a---b---c---d---e---HEAD
我想要得到一个包含提交x y z的日志。
git diff HEAD…Branch给出这些提交
然而,git log HEAD…Branch给出x y z c d e。
In the context of a revision list, A...B is how git-rev-parse defines it. git-log takes a revision list. git-diff does not take a list of revisions - it takes one or two revisions, and has defined the A...B syntax to mean how it's defined in the git-diff manpage. If git-diff did not explicitly define A...B, then that syntax would be invalid. Note that the git-rev-parse manpage describes A...B in the "Specifying Ranges" section, and everything in that section is only valid in situations where a revision range is valid (i.e. when a revision list is desired).
要获得只包含x, y和z的日志,请尝试git log HEAD..branch(两个点,而不是三个点)。这与git日志分支相同——而不是HEAD,这意味着所有在分支上的提交都不在HEAD上。