git 分支之间的git视觉差异

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12912985/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 14:47:01  来源:igfitidea点击:

git visual diff between branches

gitdiff

提问by Snowcrash

This answer is great for seeing a visual diff between two files that are checked into git: How do I view 'git diff' output with a visual diff program?

这个答案非常适合查看检入 git 的两个文件之间的视觉差异: 如何使用视觉差异程序查看“git diff”输出?

However, I'd like to see a visual diff between two branches. So far, my best bet seems to be:

但是,我希望看到两个分支之间的视觉差异。到目前为止,我最好的选择似乎是:

git diff --name-status master dev

which isn't very informative and not very visual.

这不是很有用,也不是很直观。

Is there anything better out there?

那里有更好的吗?

回答by alex

Use git diffwith a range.

使用git diff范围

git diff branch1..branch2

This will compare the tips of each branch.

这将比较每个分支的提示。

If you really want some GUI software, you can try something like SourceTreewhich supports Mac OS X and Windows.

如果你真的想要一些 GUI 软件,你可以尝试像SourceTree这样支持 Mac OS X 和 Windows 的软件。

回答by Tormod Hystad

To see a visual diff of all differences between two branches I like to merge the two branches - WITHOUT committing the merge - and then use git guior git Extensions to get an overview of the differences.

要查看两个分支之间所有差异的视觉差异,我喜欢合并两个分支 - 不提交合并 - 然后使用git guigit Extensions 来概述差异。

Git command line for merging without commiting:

用于合并而不提交的 Git 命令行:

git checkout branchA
git merge --no-commit --no-ff branchB


Then when done, you can undo the merge with

然后完成后,您可以撤消合并

git merge --abort

(h/t to @jcugat's for the comment)

(h/t to @jcugat 的评论)

回答by Kamal Reddy

In case you are using Intellij Idea IDE, you could just use the compare option in the branch.

如果您使用的是 Intellij Idea IDE,则可以在分支中使用 compare 选项。

enter image description here

在此处输入图片说明

回答by Martin

You can also do this easily with gitk.

您也可以使用 gitk 轻松完成此操作。

> gitk branch1 branch2

First click on the tip of branch1. Now right-click on the tip of branch2 and select Diff this->selected.

首先单击 branch1 的尖端。现在右键单击 branch2 的尖端并选择 Diff this->selected。

回答by Oversearch

For those of you on Windows using TortoiseGit, you can get a somewhat visual comparison through this rather obscure feature:

对于那些在 Windows 上使用 TortoiseGit 的人,您可以通过这个相当晦涩的功能获得一些视觉上的比较:

  1. Navigate to the folder you want to compare
  2. Hold down shiftand right-click it
  3. Go to TortoiseGit -> Browse Reference
  4. Use ctrlto select two branches to compare
  5. Right-click your selection and click "Compare selected refs"
  1. 导航到要比较的文件夹
  2. 按住shift并右键单击它
  3. 转到 TortoiseGit -> 浏览参考
  4. 使用ctrl选择两个分支比较
  5. 右键单击您的选择,然后单击“比较选定的参考”

Source: http://wikgren.fi/compare-diff-branches-in-tortoise-git-or-how-to-preview-changes-before-doing-a-merge/

资料来源:http: //wikgren.fi/compare-diff-branches-in-tortoise-git-or-how-to-preview-changes-before-doing-a-merge/

回答by Jordan Parker

If you are using OSX or Windows 7+, Atlassian SourceTreeworks very well for this. It is free.

如果您使用的是 OSX 或 Windows 7+,Atlassian SourceTree 对此非常有效。这是免费的。

You can see staged changes in a side-by-side diff setup, and you easily compare local with remote and any other two branches. When multiple files are selected, the diff shows up as below:

您可以在并行差异设置中看到分阶段的更改,并且您可以轻松地将本地与远程和任何其他两个分支进行比较。When multiple files are selected, the diff shows up as below:

enter image description here

在此处输入图片说明

Assuming you have checked out a feature branch and you want to see the diff against 'master', right-click on the 'master' branch and select "Diff against current"

假设您已经签出一个功能分支,并且想要查看与“master”的差异,请右键单击“master”分支并选择“与当前的差异”

Unfortunately, it doesn't seem as if it will be available on *nix distributions anytime soon.

不幸的是,它似乎不会很快在 *nix 发行版上可用。

回答by Paul Kohler

Try "difftool" (assuming you have diff tools setup) - see https://www.kernel.org/pub/software/scm/git/docs/git-difftool.html

尝试“difftool”(假设您设置了 diff 工具) - 请参阅https://www.kernel.org/pub/software/scm/git/docs/git-difftool.html

I find name statusgood for the summary but difftoolwill iterate the changes (and the -doption gives you the directory view), e.g.

我发现名称状态对摘要有好处,但difftool将迭代更改(并且该-d选项为您提供目录视图),例如

$ git difftool their-branch my-branch

Viewing: 'file1.txt'
Launch 'bc3' [Y/n]:
...

Or as @rsilva4 mentioned with -dand default to your current branch it is just - e.g. compare to master:

或者正如@rsilva4 提到的-d并且默认为您当前的分支,它只是 - 例如与 master 比较:

$  git difftool -d master..

...and yes - there are many variations - https://www.kernel.org/pub/software/scm/git/docs/git-reset.html

...是的 - 有很多变化 - https://www.kernel.org/pub/software/scm/git/docs/git-reset.html

回答by Arron

If you're using github you can use the website for this:

如果您使用的是 github,您可以使用该网站:

github.com/url/to/your/repo/compare/SHA_of_tip_of_one_branch...SHA_of_tip_of_another_branch

github.com/url/to/your/repo/compare/SHA_of_tip_of_one_branch...SHA_of_tip_of_another_branch

That will show you a compare of the two.

这将向您展示两者的比较。

回答by Mahmoodvcs

In GitExtensionsyou can select both branches in revision grid with Ctrlpressed. Then you can see files that differ between those branches. When you select a file you will see diff for it.

GitExtensions 中,您可以通过Ctrl按下选择修订网格中的两个分支。然后您可以看到这些分支之间不同的文件。当您选择一个文件时,您会看到它的差异。

Taken from here

取自这里

回答by Snowcrash

UPDATE

更新

Mac: I now use SourceTree. Thoroughly recommended. I especially like the way you can stage / unstage hunks.

Mac:我现在使用 SourceTree。彻底推荐。我特别喜欢你可以上演/不上演帅哥的方式。

Linux: I've had success with:

Linux:我在以下方面取得了成功:

  • smartgit
  • GitKraken
  • meld
  • 聪明的
  • 海妖
  • meld

E.g. to install smartgiton Ubuntu:

例如smartgit在 Ubuntu上安装:



This does the job:

这可以完成以下工作:

git-diffall with a GUI diff tool like meld. See point 5 here:

git-diffall 带有像 meld 这样的 GUI diff 工具。请参阅此处的第 5 点:

http://rubyglazed.com/post/15772234418/git-ify-your-command-line

http://rubyglazed.com/post/15772234418/git-ify-your-command-line

There's a nice post about git and meld here: http://nathanhoad.net/how-to-meld-for-git-diffs-in-ubuntu-hardy

这里有一篇关于 git 和 meld 的好文章:http: //nathanhoad.net/how-to-meld-for-git-diffs-in-ubuntu-hardy