从一个分支被分支到当前分支之后,最好的方法是什么?目前我的解决方案是:

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。


当前回答

我发现

git diff <branch_with_changes> <branch_to_compare_to>

更有用,因为你不只是得到提交消息,而是整个diff。如果你已经在分支上,你想要看到的变化,(例如)想要看到master的变化,你可以使用:

git diff HEAD master

其他回答

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上。

在那里抛出一个-p来查看一些FILE CHANGES

git log -p master..branch

做一些别名:

alias gbc="git branch --no-color | sed -e '/^[^\*]/d' -e 's/* \\(.*\\)/\1/'"

alias gbl='git log -p master..\`gbc\`'

查看分支的唯一提交:

gbl

查看当前分支自master分支以来的日志:

Git日志管理…

如果你当前在master上,查看不同分支的日志,因为它是从master上分支的:

Git日志

我发现

git diff <branch_with_changes> <branch_to_compare_to>

更有用,因为你不只是得到提交消息,而是整个diff。如果你已经在分支上,你想要看到的变化,(例如)想要看到master的变化,你可以使用:

git diff HEAD master
git cherry branch [newbranch]

当你在主分支时,完全按照你的要求做。

我也很喜欢:

git diff --name-status branch [newbranch]

这不是你要问的,但在相同的上下文中仍然非常有用。