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

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推送

把这些函数放到你的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推送

把这些函数放到你的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 diff <branch_with_changes> <branch_to_compare_to>

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

git diff HEAD master

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

git diff master...

它结合了以下几个特点:

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

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

Git日志管理…

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

Git日志

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

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