git difftool, open all diff files immediately, not in serial

核能气质少年 提交于 2019-12-17 02:33:27

问题


The default git diff behavior is to open each diff file in serial (wait for previous file to be closed before opening next file).

I'm looking for a way to open all the files at once - in BeyondCompare for example this would open all the files in tabs within the same BC window.

This would make it easier to review a complex set of changes; flick back and forwards between the diff files and ignore unimportant files.


回答1:


Starting with git v1.7.11, you can use git difftool --dir-diff to perform a directory diff.

This feature works well with Meld 3.14.2 for example, and lets you browse all modified files:

git difftool --dir-diff --tool=meld HEAD~ HEAD

This is a handy Bash function:

git-diff-meld() (
  git difftool --dir-diff --tool=meld "${1:-HEAD~}" "${2:-HEAD}"
)

The answer that follows applies to git installations older than v1.7.11.


This same question was asked on the git mail list.

I put together a shell script based on that email thread which performs a directory diff between arbitrary commits.

Starting with git v1.7.10, the git-diffall script is included in the contrib of the standard git installation.

For versions before v1.7.10, you can install from the git-diffall project on GitHub.

Here is the project description:

The git-diffall script provides a directory based diff mechanism for git. The script relies on the diff.tool configuration option to determine what diff viewer is used.

This script is compatible with all the forms used to specify a range of revisions to diff:

1) git diffall: shows diff between working tree and staged changes
2) git diffall --cached [<commit>]: shows diff between staged changes and HEAD (or other named commit)
3) git diffall <commit>: shows diff between working tree and named commit
4) git diffall <commit> <commit>: show diff between two named commits
5) git diffall <commit>..<commit>: same as above
6) git diffall <commit>...<commit>: show the changes on the branch containing and up to the second , starting at a common ancestor of both <commit>

Note: all forms take an optional path limiter [--] [<path>]

This script is based on an example provided by Thomas Rast on the Git list.




回答2:


Here's what I settled on...

Copy the following code to a file called git-diffall (no extension):

#!/bin/sh
git diff --name-only "$@" | while read filename; do
    git difftool "$@" --no-prompt "$filename" &
done

Place the file in the cmd folder of your git install dir (eg C:\Program Files (x86)\Git\cmd)

And use like you would git diff:

git diffall
git diffall HEAD
git diffall --cached 
git diffall rev1..rev2
etc...

Notes: The key to it is the & param which tells the external diff command to run in a background task so files are processed immediately. In the case of BeyondCompare this opens one screen with each file in its own tab.




回答3:


meld has a neat feature that if you give it a directory under source control (Git, Mercurial, Subversion, Bazaar and probably others) it will automatically list all the changed files and you can double-click to view the individual differences.

IMO it's much easier to type meld . and have it figure out the VCS than configure your VCS to launch meld. Plus you can use the same command no matter what VCS your project happens to be using, which is great if you switch between them a lot.

The only downside is it is slower for meld to scan for changes than to be passed the changes from git/hg/svn, though whether it's slow enough to be a problem will depend on how you're using it I'm sure.




回答4:


I did find this method (GitDiff.bat and GitDiff.rb) that copies the files out to old/new temp dirs and then does a folder compare on them.

But I'd rather view the working files directly (from the working dir), as BeyondCompare has the handy feature of being able to edit the file from within the diff window which is great for quick cleanups.

Edit: a similar method here in response to my question on the git mailing list.




回答5:


git meld => https://github.com/wmanley/git-meld is an awesome script which will open a neat diff of all the files in a single window.




回答6:


Diffuse also has VCS integration. It interoperates with a plethora of other VCS, including SVN, Mercurial, Bazaar, ... For Git, it will even show three panes if some but not all changes are staged. In the case of conflicts, there will even be four panes.

Invoke it with

diffuse -m

in your Git working copy.

If you ask me, the best visual differ I've seen for a decade. (And I've tried meld, too.)




回答7:


Noticed here that Araxis Merge has a '-nowait' command option:

-nowait Prevents compare from waiting for a comparison to be closed

Maybe this returns an immediate exit code and would work, anyone experienced this? Can't find similar option for BeyondCompare...




回答8:


If all you want to do is open all the files that are currently modified, try something like:

vi $(git status | sed -n '/.*modified: */s///p')

If you are making commits of "complex sets of changes", you might want to reconsider your workflow. One of the really nice features of git is that it makes it easy for the developer to reduce complex change sets to a series of simple patches. Rather than trying to edit all of the files that are currently modified, you might want to look into

git add --patch
which will allow you to selectively stage hunks.


回答9:


I've written a powershell script that will duplicate two working trees and compare with DiffMerge. So you can do:

GitNdiff master~3 .

To compare the master branch three checkins ago with the current working tree, for instance.

Its shiny and new and probably full of bugs. One drawback is that files in your working tree that have not been added yet are copied out to both working trees. It can also be slow.

http://github.com/fschwiet/GitNdiff




回答10:


For those interested in using git-diffall on Mac OS X with Araxis, I forked the git-diffall project on github and added an AppleScript that wraps the Araxis Merge command. Note: this is a slightly modified clone of the araxisgitdiff file that ships with Araxis Merge for Mac OS X.

https://github.com/sorens/git-diffall




回答11:


The following works with meld and kdiff3

git difftool --dir-diff origin/branch1..origin/branch2

Opens all the files in a window that you can browse with ease. Can be used with changesets in place of origin/branch-name

eg: git difftool --dir-diff origin/master..24604fb72f7e16ed44115fbd88b447779cc74bb1




回答12:


You can use gitk and see all the differences at the same time



来源:https://stackoverflow.com/questions/1220309/git-difftool-open-all-diff-files-immediately-not-in-serial

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!