本文翻译自:How do I see the commit differences between branches in git?

I'm on branch-X and have added a couple more commits on top of it. 我在分支-X上,并在其上添加了几个提交。 I want to see all the differences between MASTER and the branch that I am on in terms of commits. 我想看看MASTER和我提交的分支之间的所有区别。 I could just do a 我可以做一个

git checkout master
git log

and then a 然后一个

git checkout branch-X
git log

and visually diff these, but I'm hoping for an easier, less error-prone method. 并且在视觉上区分这些,但我希望有一种更简单,更不容易出错的方法。


#1楼

参考:https://stackoom.com/question/WB2f/如何在git中看到分支之间的提交差异


#2楼

You can easily do that with 你可以轻松地做到这一点

git log master..branch-X

That will show you commits that branch-X has but master doesn't. 这将显示你提交的分支-X但主却没有。


#3楼

你可以得到一个非常好的视觉输出,你的分支与此有何不同

git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative master..branch-X

#4楼

If you are on Linux, gitg is way to go to do it very quickly and graphically. 如果您使用的是Linux, gitg可以非常快速地以图形方式完成。

If you insist on command line you can use: 如果你坚持使用命令行,你可以使用:

git log --oneline --decorate

To make git log nicer by default, I typically set these global preferences: 为了使git log默认更好,我通常设置这些全局首选项:

git config --global log.decorate true
git config --global log.abbrevCommit true

#5楼

if you want to use gitk: 如果你想使用gitk:

gitk master..branch-X

it has a nice old school GUi 它有一个很好的老派GUi


#6楼

I think it is matter of choice and context.I prefer to use 我认为这是选择和背景的问题。我更喜欢使用

git log origin/master..origin/develop --oneline --no-merges

It will display commits in develop which are not in master branch. 它将显示不在master分支中的develop中的提交。

If you want to see which files are actually modified use 如果要查看实际修改了哪些文件,请使用

git diff --stat origin/master..origin/develop --no-merges

If you don't specify arguments it will display the full diff. 如果不指定参数,它将显示完整的差异。 If you want to see visual diff, install meld on linux, or WinMerge on windows. 如果你想看到visual diff,请在linux上安装meld ,或在windows上安装WinMerge Make sure they are the default difftools .Then use something like 确保它们是默认的difftools。然后使用类似的东西

git difftool -y origin/master..origin/develop --no-merges

In case you want to compare it with current branch. 如果您想将其与当前分支进行比较。 It is more convenient to use HEAD instead of branch name like use: 使用HEAD代替分支名称比使用更方便:

git fetch
git log origin/master..HEAD --oneline --no-merges

It will show you all the commits, about to be merged 它将向您显示即将合并的所有提交

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐