How to show relative paths in git diff command?

前端 未结 2 952
感情败类
感情败类 2021-01-18 09:33

It works in this way:

MYPC /d/home/project/some/path (master)
$ git diff --name-only --cached
root.txt
some/path/relative.txt

I.e. it shows

2条回答
  •  逝去的感伤
    2021-01-18 10:31

    git status -s already outputs relative paths that can be easily isolated.

    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
    

提交回复
热议问题