如何让git difftool总是导出绝对路径 [英] how to make git difftool to always export absolute paths
问题描述
当使用'git difftool'时,当其中一个文件是最新版本时,它将相对路径传递给外部差异应用程序。
〜/ .gitconfig
$ $ p $ code $ [difftoolecho]
cmd = echo $ LOCAL $ REMOTE
path =
[diff]
tool = echo
示例命令
git difftool e3d654bc65404b9229abc0251a6793ffbfccdee3 6c6b5fd34196402e4fa0e8cf42f681d9fbd5359f
查看:'app / views / shared / _graph.html.slim'
启动'echo'[Y / n]:y
app / views / shared / _graph.html.slim /var/folders/fs/3pgvhwkj2vq4qt3q6n74s5880000gn/T//XGFoyj__graph.html.slim
在这个例子中, app / views / shared / _graph.html.slim
是相对路径,外部diff应用程序,因为它是相对的diff应用程序不知道如何打开它。
如何使'git difftool'总是导出绝对路径?
这是基于hlovdal和VonC答案的解决方案,我最终使用它。
〜/ .git_absolute_path.sh
#!/ bin / sh
FILE_PATH =$ 1
case$ FILE_PATH
in
/ *)
NEW_PATH =$ FILE_PATH
;;
*)
NEW_PATH =`git rev-parse --show-toplevel` /$ FILE_PATH
;;
esac
echo$ NEW_PATH
〜/。 gitconfig
$ b
[difftoolecho]
cmd = echo`〜/ .git_absolute_path.sh $ LOCAL``〜 /.git_absolute_path.sh $ REMOTE`
path =
[mergetoolecho]
cmd = echo`〜/ .git_absolute_path.sh $ LOCAL``〜/ .git_absolute_path.sh $ REMOTE ``〜/ .git_absolute_path.sh $ BASE``〜/ .git_absolute_path.sh $ MERGED`
trustExitCode = true
[diff]
工具= echo
这里的区别在于我们正在重复使用每个路径的单个脚本。
When using 'git difftool' it passes relative path to external diff application when one of the files is the latest version.
~/.gitconfig
[difftool "echo"]
cmd = echo $LOCAL $REMOTE
path =
[diff]
tool = echo
example command
git difftool e3d654bc65404b9229abc0251a6793ffbfccdee3 6c6b5fd34196402e4fa0e8cf42f681d9fbd5359f
Viewing: 'app/views/shared/_graph.html.slim'
Launch 'echo' [Y/n]: y
app/views/shared/_graph.html.slim /var/folders/fs/3pgvhwkj2vq4qt3q6n74s5880000gn/T//XGFoyj__graph.html.slim
In this example app/views/shared/_graph.html.slim
is relative path which would be passed to external diff application and since it is relative the diff application doesn't know how to open it.
How can I make 'git difftool' to ALWAYS export absolute paths?
This is solution based on hlovdal and VonC answers which I've ended up using.
~/.git_absolute_path.sh
#!/bin/sh
FILE_PATH="$1"
case "$FILE_PATH"
in
/*)
NEW_PATH="$FILE_PATH"
;;
*)
NEW_PATH=`git rev-parse --show-toplevel`/"$FILE_PATH"
;;
esac
echo "$NEW_PATH"
~/.gitconfig
[difftool "echo"]
cmd = echo `~/.git_absolute_path.sh $LOCAL` `~/.git_absolute_path.sh $REMOTE`
path =
[mergetool "echo"]
cmd = echo `~/.git_absolute_path.sh $LOCAL` `~/.git_absolute_path.sh $REMOTE` `~/.git_absolute_path.sh $BASE` `~/.git_absolute_path.sh $MERGED`
trustExitCode = true
[diff]
tool = echo
the difference here is that we are reusing the single script for each path.
这篇关于如何让git difftool总是导出绝对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!