How to see code changes after git pull?

后端 未结 5 1258
孤城傲影
孤城傲影 2020-12-07 09:19

I would like to inspect any code changes after doing a git pull. Currently it\'s just showing me which files changes. How can I see what code changed?

5条回答
  •  臣服心动
    2020-12-07 09:52

    Before pulling

    You can review changes as @iblue says with a fetch and diff before merging:

    $ git fetch
    $ git diff master...origin/master
    

    Note the triple period, which means diff against the shared parent and origin/master (commits marked x below):

    SP---o---o [master]
      \
       x---x [origin/master]
    

    Just after a pull

    The very first line in the output of a pull looks like this:

    $ git pull
    Updating 37b431a..b2615b4
    ...
    

    You can then simply do:

    $ git diff 37b431a..b2615b4
    

    Or whatever other command:

    $ git log --name-status 37b431a..b2615b4
    

    Later on

    If it has been a while since you pulled, and you wish to know what changes were brought in by the last pull, you can look it up with:

    $ git reflog | grep -A1 pull | head -2
    

    which will show the hash after the pull followed by the hash before the pull:

    b2615b4 HEAD@{0}: pull : Fast-forward
    37b431a HEAD@{1}: checkout: moving from v6.1 to master
    

    You can then do the same thing with these two hashes:

    git diff 37b431a..b2615b4
    

提交回复
热议问题