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

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


git cherry branch [newbranch]

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

我也很喜欢:

git diff --name-status branch [newbranch]

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


这类似于我在上面发布的答案:预览Git推送

把这些函数放到你的Bash配置文件中:

Gbout - git分支输出 Gbin - git分支传入

你可以这样使用:

如果在master上:gbin branch1 <——this 我会告诉你branch1和 不在master中 如果在master: gbout Branch1 <——这将显示什么是 在master中,它不在分支1中

这将适用于任何分支。

function parse_git_branch {
  git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
}

function gbin {
    echo branch \($1\) has these commits and \($(parse_git_branch)\) does not
    git log ..$1 --no-merges --format='%h | Author:%an | Date:%ad | %s' --date=local
}

function gbout {
    echo branch \($(parse_git_branch)\) has these commits and \($1\) does not
    git log $1.. --no-merges --format='%h | Author:%an | Date:%ad | %s' --date=local
}

git log --cherry-mark --oneline from_branch...to_branch

(3个点)但有时它会显示“+”而不是“=”


您希望看到的是传出提交的列表。你可以用

git log master..branchName 

or

git log master..branchName --oneline

在这里,我假设“branchName”是作为“master”的跟踪分支创建的。

类似地,要查看传入的更改,您可以使用:

git log branchName..master

在那里抛出一个-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

我发现

git diff <branch_with_changes> <branch_to_compare_to>

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

git diff HEAD master

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

Git日志管理…

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

Git日志


当已经在有问题的分支使用

git diff master...

它结合了以下几个特点:

它非常短 显示实际的变化 允许主人向前移动


在Git 2.30(2021年第一季度)中,“Git diff A…B(man)”学会了“Git diff—merge-base A B(man)”,这是说同样事情的一个更长的简写。

因此,你可以使用git diff——merge-base <branch> HEAD来做到这一点。这应该等价于git diff <branch>…HEAD,但没有在diff中使用范围符号的混乱。