Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

git difftool runs git diff

I am obviously overlooking something very simple here, but I am not seeing it. The command

webstorm diff ~/test.txt ~/test2.txt

runs the JetBrains graphical diff tool. I am running git 1.8.3.2 and have a git .config that includes

[diff]
    tool = webstorm
[difftool "webstorm"]
    cmd = webstorm diff $(cd $(dirname "$LOCAL") && pwd)/$(basename "$LOCAL") $(cd $(dirname "$REMOTE") && pwd)/$(basename "$REMOTE")
[difftool]
    prompt = false

and when I run the command

git difftool ~/test.txt ~/test2.txt

I get the following in the terminal window:

diff --git a/home/mark/test.txt b/home/mark/test2.txt
index 7379ce2..6ce16f1 100644
--- a/home/mark/test.txt
+++ b/home/mark/test2.txt
@@ -1,2 +1,2 @@
-blah
+bluergh

What am I doing wrong / not doing?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Run:

GIT_TRACE=1 git difftool --tool-help

to print a list of diff tools that may be used with --tool, and which are not available.


Secondly I believe the following simplified example may work better:

[difftool "webstorm"]
  cmd = webstorm diff "$LOCAL" "$REMOTE"

Or by specifying the path to the binary or script, e.g.

[difftool]
  prompt = NO
  external = /usr/local/bin/diffmerge

Check the diff configuration by:

git config --get-regex diff

Or more specifically (replace webstorm with your tool name):

git config --get difftool.webstorm.cmd

If still doesn't work, test it on the new repository, e.g. by following these commands:

mkdir ~/git_test && cd ~/git_test
git init && touch file && git add file && git commit -m'Adds file' -a
echo changed >> file
GIT_TRACE=1 git difftool

If above works, then make sure your repository config doesn't have anything unexpected, e.g.

more "$(git rev-parse --show-toplevel)"/.git/config

If you're in merge state (check by git status), you need to use mergetool instead, e.g.

git mergetool

Add -t tool to specify which tool. List available by git mergetool --tool-help.


See also man git-difftool:

CONFIG VARIABLES
       git difftool falls back to git mergetool config variables when the difftool equivalents have not been
       defined.

       diff.tool
           The default diff tool to use.

       diff.guitool
           The default diff tool to use when --gui is specified.

       difftool.<tool>.path
           Override the path for the given tool. This is useful in case your tool is not in the PATH.

       difftool.<tool>.cmd
           Specify the command to invoke the specified diff tool.

           See the --tool=<tool> option above for more details.

       difftool.prompt
           Prompt before each invocation of the diff tool.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...