本文介绍了如何在git diff命令中显示相对路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
它以这种方式工作:
MYPC /d/home/project/some/path (master)
$ git diff --name-only --cached
root.txt
some/path/relative.txt
即它显示了来自GIT根目录的路径,但是我需要来自当前目录的相对路径.
I.e. it shows path from the GIT root, but I need relative paths from current directory.
预期结果:
$ git diff --name-only --cached --AND_SOME_OPTION
../../root.txt
relative.txt
按常识,它应该像git status
一样工作.
In common sense, it should work like git status
.
PS --relative
选项不起作用,因为它将显示此目录中的文件.在我们的示例中,它将仅显示relative.txt
.
P.S.The --relative
option doesn't work because it will show files from this directory.In our example it will show only relative.txt
.
P.P.S
使用--git-dir
不能正常工作:
$ git --git-dir=$(git rev-parse --show-toplevel)/.git diff --cached --name-only
root.txt
some/path/relative.txt
推荐答案
git status -s
已经输出了可以轻松隔离的相对路径.
git status -s
already outputs relative paths that can be easily isolated.
如果需要使用git diff
,则可以将输出通过管道传输到realpath
(如果可用):
If you need to use git diff
, you can pipe the output to realpath
, if available:
$ git diff --name-only | \
xargs -I '{}' realpath --relative-to=. $(git rev-parse --show-toplevel)/'{}'
../../root.txt
relative.txt
这篇关于如何在git diff命令中显示相对路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!