(git) diff output relative path?

后端 未结 2 2026
说谎
说谎 2020-12-20 12:00

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:



        
2条回答
  •  甜味超标
    2020-12-20 12:24

    Seems like --src-prefix and --dst-prefix are what you're asking for:

    $ cd .../git/builtin
    $ ed - var.c << end
    > 0a
    > xxx
    > .
    > wq
    > end
    $ git diff
    diff --git a/builtin/var.c b/builtin/var.c
    index aedbb53..5210013 100644
    --- a/builtin/var.c
    +++ b/builtin/var.c
    @@ -1,3 +1,4 @@
    +xxx
     /*
      * GIT - The information manager from hell
      *
    

    (so far, pretty standard; now:)

    $ git diff --src-prefix=a/new/ --dst-prefix=b/new/
    diff --git a/new/builtin/var.c b/new/builtin/var.c
    index aedbb53..5210013 100644
    --- a/new/builtin/var.c
    +++ b/new/builtin/var.c
    @@ -1,3 +1,4 @@
    +xxx
     /*
      * GIT - The information manager from hell
      *
    

    You can combine this with --relative:

    $ git diff --relative --src-prefix=a/new/ --dst-prefix=b/new/
    diff --git a/new/var.c b/new/var.c
    index aedbb53..5210013 100644
    --- a/new/var.c
    +++ b/new/var.c
    @@ -1,3 +1,4 @@
    +xxx
     /*
      * GIT - The information manager from hell
      *
    $ 
    

提交回复
热议问题