View differences of branches with meld?

2019-01-08 03:01发布

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?

At the moment I do the following steps:

  1. Rename folder of working copy
    For example mv /projectA /projectA_master)
  2. Clone the project again
    git clone url
  3. Switch to devel branch
    cd projectA && git -b devel origin/devel
  4. View differences with 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.

9条回答
干净又极端
2楼-- · 2019-01-08 03:22

It is important to say that using git difftool -d you can still edit your 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 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.

Yet more interesting option is comparison of current working dir with stash. You can do that by simply typing:

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.

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.

查看更多
Root(大扎)
3楼-- · 2019-01-08 03:26

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.)

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 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:

git difftool -d ABC
查看更多
Viruses.
4楼-- · 2019-01-08 03:27

I think a easy way for doing this is using git reset --soft:

Goal: compare differences between branch_a and branch_b with meld

git checkout branch_a
git checkout -b do_diff
git reset --soft branch_b
meld .
查看更多
叛逆
5楼-- · 2019-01-08 03:33

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-meld scripts.

Configure git

git config --global diff.tool meld

Use it

git difftool -d topic             // -d is --dir-diff
git difftool -d master..topic

For 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
查看更多
Anthone
6楼-- · 2019-01-08 03:36

If you have clean working directory and clean index (or don't care about it) then this what you want:

git diff master..devel | patch -p1 && meld . && git reset --hard
查看更多
贪生不怕死
7楼-- · 2019-01-08 03:41

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:

http://gist.github.com/498628

Of course, you'll lose any changes made via meld, but it's quite nice for a quick overview of the differences, I think.

查看更多
登录 后发表回答