how to show differences between some or all files? GIT

后端 未结 3 1826
半阙折子戏
半阙折子戏 2020-12-31 11:01

As in the subject: how to show differences betwen some or all files?

Sorry i\'ve screwed up my question. I meant differences betwen branches for one or multiple or a

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-31 11:15

    Or perhaps a bit more helpful:

    git diff   -- path/to/file.cpp path/to/anotherfile.cpp path/to/subdir
    

    You can also (in e.g. bash)

    git diff {,}:path/to/file.cpp
    

    This way you can even

    git diff :path/to/file.cpp :path/to/anotherfile.cpp
    

    which is quite insane powerful, IMHO.

    Replace and by any name of tag, branch (local or remote) or direct sha1 hash of a commit (this is known as a commit-ish)

    To get really funky, you can specify tree-ish or blob hashes if you want. Do something completely silly with this for a sample:

    $ git ls-tree HEAD^ | grep blob | sort -R | head -2
    100644 blob 27785581e788049ac805fab1d75744dd7379735d    .gitignore
    100644 blob 2821a5271ffd8e6b11bb26b8571f57e88ab81f38    TESTING
    
    $ git diff --stat 2821a5271ffd8e6b11bb26b8571f57e88ab81f38 aa96765714a3058068c4425d801fab4b64e26066
     ...f38 => aa96765714a3058068c4425d801fab4b64e26066 |  155 +++++++++++++++++---
     1 files changed, 135 insertions(+), 20 deletions(-)
    

    Now you won't usually do this, unless you have several versions of the 'same' file in you repo (which is iffy, if you ask me).

提交回复
热议问题