View differences of branches with meld?

后端 未结 8 720
终归单人心
终归单人心 2020-11-30 16:30

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<

相关标签:
8条回答
  • 2020-11-30 16:52

    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.

    0 讨论(0)
  • 2020-11-30 16:52

    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.

    0 讨论(0)
  • 2020-11-30 16:57

    For Meld on macOS, add this to your ~/.gitconfig as recommended by the maintainer of the macOS application, yousseb:

    [diff]
      tool = meld
    [difftool]
      prompt = false
    [difftool "meld"]
      trustExitCode = true
      cmd = open -W -a Meld --args \"$LOCAL\" \"$REMOTE\"
    [merge]
      tool = meld
    [mergetool]
      prompt = false
    [mergetool "meld"]
      trustExitCode = true
      cmd = open -W -a Meld --args --auto-merge \"$LOCAL\" \"$BASE\" \"$REMOTE\" --output=\"$MERGED\"
    

    You can omit the merge configs if you would like.

    @GutenYe's answer didn't work out for me due to automatic escaping and/or something with zsh.

    0 讨论(0)
  • 2020-11-30 17:03

    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.

    0 讨论(0)
  • 2020-11-30 17:10

    In git V1.7.9 you can compare two commits without the commandline:

    You must configure in 'git gui' edit options, global: "Use merge tool: meld".

    Start gitk, select a commit, right click another commit > "diff this --> selected". Under 'patch' right click a file > "external diff".

    meld will start and display the still selected, first commit on the right side.

    0 讨论(0)
  • 2020-11-30 17:13

    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
    
    0 讨论(0)
提交回复
热议问题