git 查看分支与合并的差异?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2006032/
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
View differences of branches with meld?
提问by Marten Bauer
I know that I can view the difference between HEAD and current state with meld .
. But how can I view the differences between branches, for example master
and devel
with meld?
我知道我可以使用meld .
. 但我怎么能查看分支之间的差异,例如master
和devel
与MELD?
At the moment I do the following steps:
目前我执行以下步骤:
- Rename folder of working copy
For examplemv /projectA /projectA_master
) - Clone the project again
git clone url
- Switch to
devel
branchcd projectA && git -b devel origin/devel
- View differences with meld
meld /projectA_Master projectA
- 重命名工作副本的文件夹
例如mv /projectA /projectA_master
) - 再次克隆项目
git clone url
- 切换到
devel
分支cd projectA && git -b devel origin/devel
- 查看与 meld 的差异
meld /projectA_Master projectA
Isn't there an easier way to get the same result in meld? I only need it to review the changes and not primarily for merging.
没有更简单的方法可以在 meld 中获得相同的结果吗?我只需要它来查看更改,而不是主要用于合并。
采纳答案by Will Manley
I also found this issue annoying so I've made git meld which allows a more comfortable way of diffing arbitrary commits against the working tree or the staging area. You can find it at https://github.com/wmanley/git-meld. It's a bit like Mark's script but works for comparing any arbitrary commit or the staging area or the working directory against any of the others. If one of the things you are comparing against is the working tree then that is read-write also so you don't lose your changes.
我也发现这个问题很烦人,所以我制作了 git meld,它允许一种更舒适的方式来区分对工作树或暂存区的任意提交。你可以在https://github.com/wmanley/git-meld找到它。它有点像 Mark 的脚本,但适用于将任意提交或暂存区或工作目录与其他任何内容进行比较。如果您要比较的其中一件事是工作树,那么它也是可读写的,因此您不会丢失更改。
回答by J?rg W Mittag
Short & sweet:
简短而甜蜜:
git config --global diff.tool meld
This configures Git to use meld
as the diff tool. (You don't need to specify the command line arguments, support for meld
is built into Git.)
这会将 Git 配置为meld
用作差异工具。(您不需要指定命令行参数,meld
Git 内置了对 的支持。)
Then, if you want a graphical diff instead of a textual one, you simply invoke git difftool
instead of git diff
(they both take the same arguments). In your case:
然后,如果您想要图形差异而不是文本差异,您只需调用git difftool
而不是git diff
(它们都采用相同的参数)。在你的情况下:
git difftool master..devel
Update: If you don't want the one-file-at-a-time diff, but instead want to use meld's "subdirectory" view with all the changes between the two branches, note the -d
or --dir-diff
option for git difftool
. For example, when I'm on branch XYZ and I want to see what is different between this and branch ABC, I run this:
更新:如果你不想要的文件,在-A-时间差异,而是要与所有的两个分支之间的变化使用MELD的“子目录”的观点,注意-d
或--dir-diff
供选择git difftool
。例如,当我在分支 XYZ 上并且我想看看它与分支 ABC 之间有什么不同时,我运行以下命令:
git difftool -d ABC
回答by GutenYe
Starting with git v1.7.11, you can use git difftool --dir-diff
to perform a directory diff. Which works quite well with meld wihout https://github.com/wmanley/git-meldscripts.
从 git v1.7.11 开始,您可以使用git difftool --dir-diff
来执行目录差异。这对于没有https://github.com/wmanley/git-meld脚本的meld 非常有效。
Configure git
配置git
git config --global diff.tool meld
Use it
用它
git difftool -d topic // -d is --dir-diff
git difftool -d master..topic
For macOS
对于 macOS
brew cask install meld
git config --global difftool.meld.cmd 'open -W -a Meld --args \"$LOCAL\" \"$PWD/$REMOTE\"'
git config --global difftool.meld.trustExitCode true
回答by Piotr Jurkiewicz
It is important to say that using git difftool -d
you can still edityour working files in Meld and save them. In order to achieve that you need to compare some branch to your current working tree, for example:
重要的是,使用git difftool -d
您仍然可以在 Meld 中编辑您的工作文件并保存它们。为了实现这一点,您需要将某个分支与当前的工作树进行比较,例如:
git difftool -d branchname
Meld will be showing that both left and right directories are located in /tmp. However, files in the right directory are actually symbolic links to your files in the current working directory (does not apply to Windows). So you can edit them right in Meld and when you save them your changes will be saved in your working dir.
Meld 将显示左右目录都位于 /tmp 中。但是,正确目录中的文件实际上是指向当前工作目录中文件的符号链接(不适用于 Windows)。所以你可以直接在 Meld 中编辑它们,当你保存它们时,你的更改将保存在你的工作目录中。
Yet more interesting option is comparison of current working dir with stash. You can do that by simply typing:
更有趣的选择是将当前工作目录与 stash 进行比较。您可以通过简单地输入:
git difftool -d stash
Then you can transfer some changes from stash (left window) to your current working copy (right window), without using git stash pop/apply
and avoiding bothersome conflict resolution which may be induced by this commands.
然后,您可以将一些更改从 stash(左窗口)转移到您当前的工作副本(右窗口),而无需使用git stash pop/apply
和避免可能由此命令引起的麻烦的冲突解决方法。
I think that it can significantly boost up workflow with stashes. You can gradually transfer changes from stash to working copy and commit them one by one, introducing some another changes if you want.
我认为它可以通过隐藏显着提高工作流程。您可以逐渐将更改从 stash 转移到工作副本并一个一个提交,如果需要,可以引入一些其他更改。
回答by Mark Longair
Although it seems from the other answers as if there's not a way to do this directly in the git repository at the moment, it's easy (thanks to the answer to another question:)) to write a script that will extract the trees of two commits to temporary directories and run meld on them, removing both directories when meld exits:
尽管从其他答案看来,目前似乎没有办法直接在 git 存储库中执行此操作,但编写一个脚本来提取两个提交的树很容易(感谢另一个问题的答案:))到临时目录并对它们运行 meld,当 meld 退出时删除两个目录:
Of course, you'll lose any changes made via meld, but it's quite nice for a quick overview of the differences, I think.
当然,您将丢失通过 meld 所做的任何更改,但我认为快速概览差异非常好。
回答by realtime
I think a easy way for doing this is using git reset --soft
:
我认为这样做的一个简单方法是使用git reset --soft
:
Goal: compare differences between branch_a and branch_b with meld
目标:使用 meld 比较 branch_a 和 branch_b 之间的差异
git checkout branch_a
git checkout -b do_diff
git reset --soft branch_b
meld .
回答by Stefan Forster
In git V1.7.9 you can compare two commits without the commandline:
在 git V1.7.9 中,您可以在没有命令行的情况下比较两个提交:
You must configure in 'git gui' edit options, global: "Use merge tool: meld".
您必须在 'git gui' 编辑选项中进行配置,全局:“使用合并工具:meld”。
Start gitk, select a commit, right click another commit > "diff this --> selected". Under 'patch' right click a file > "external diff".
启动gitk,选择一个提交,右键单击另一个提交>“ diff this --> selected”。在“补丁”下右键单击文件>“外部差异”。
meldwill start and display the still selected, first commit on the right side.
meld将启动并在右侧显示仍然选择的第一次提交。