I like the format of git diff
and the diffstat, but sometimes I would like to use it outside of any git repository, on two arbitrary directories. Doing this introduces some undesired extra directory prefixes into the output, though, which I am having trouble getting rid of.
old
(not in any repo).new
and make some changes.git diff -p --stat old/ new/
This almost works, but unfortunately the diffstat includes {old => new}/
as a path prefix and the diff headers show a/old/...
and b/new/...
, for example:
{old => new}/src/config.h | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/old/src/config.h b/new/src/config.h
index 8158fcc..7ec16df 100644
--- a/old/src/config.h
+++ b/new/src/config.h
@@ -66,7 +66,7 @@
...
I want the diff to be entirely relative to the directories specified on the command line, thus not naming them in the resulting output at all (ie {old => new}/
should not appear and the diff headers should only be a/...
and b/...
). I do want it to include the relative path within each directory (eg src/
). ie the "correct" output would be:
src/config.h | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/config.h b/src/config.h
index 8158fcc..7ec16df 100644
--- a/src/config.h
+++ b/src/config.h
@@ -66,7 +66,7 @@
...
I would also like this to work even if old
and new
are not sibling directories -- eg I might be comparing old/
and ../foo/bar/new/
, and the output should be exactly identical to the above if they have the same contents.
If, instead of old
and new
, I name the directories a
and b
(and ensure they're siblings), then I can get the patch part to appear correctly by adding --no-prefix
, but this still outputs the wrong diffstat. (This also works if I instead run diff -ur a/ b/
, but then there's no diffstat, and it doesn't work with different directory names.)
Is there any trick I'm missing to accomplish this? Note that I'm on a Windows system, so I only have the limited set of posix tools that come with Git for Windows.
您可以将old
和new
的放在另一个文件夹中,然后将git init
放在该父文件夹中。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.