Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

(git) diff output relative path?

I need to get some diffs in my repo that are not relative to the base of the repo, but instead relative to a given base or given path.

By default I get:

git diff
diff --git a/path/to/file b/path/to/file
index 0cc125e..9bf911e 100644
--- a/path/to/file
+++ b/path/to/file

But what I want is something like:

git diff --prefix=/new/path/to
diff --git a/new/path/to/file b/new/path/to/file
index 0cc125e..9bf911e 100644
--- a/new/path/to/file
+++ b/new/path/to/file

I have looked over the --relative option (not what I am looking for), the --src/dst-prefix (these can only change the "a" or "b" parts. Am I missing something basic?

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

git diff prints paths (of changed files) from the root of the repo - no matter where you are when executing the command.

git diff --relative will print paths from the dir you are in.

So if you need paths not starting from the repo-root move down (cd) to the directory (within your repo tree) where you with your paths to start from.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...