How to see code changes after git pull?

Git

Git Problem Overview


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?

Git Solutions


Solution 1 - Git

git log --name-status -2

Will show you the names of the files that changed for the last two commits.

git log -p -2

Will show you the changes themselves.

Before you pull,

git fetch
git log --name-status origin/master..

Will show you what commits you are about to retrieve, along with the names of the files.

Solution 2 - Git

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

Solution 3 - Git

Because git pull is just a shortcut for git fetch and git merge, you can run git fetch to fetch the branches from the origin and then show the differences before merging. Like this:

git fetch                      # Load changes from remote server
git diff master origin/master  # Show differences
git merge origin/master        # Merge remote changes with local changes

If you run on a different branch than master, you should of course change the branch names in the commands above.

Solution 4 - Git

You can compare the pulled contents with the sources of immediately previous commit by,

git diff branch_name@{1}

eg:

git diff master@{1}

For comparing with the sources n commits behind,

git diff branch_name@{n}

Solution 5 - Git

You can check what get change while push and pull by this...

git log --stat

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionuweView Question on Stackoverflow
Solution 1 - GitWayne ConradView Answer on Stackoverflow
Solution 2 - GitquornianView Answer on Stackoverflow
Solution 3 - GitiblueView Answer on Stackoverflow
Solution 4 - GitKasunView Answer on Stackoverflow
Solution 5 - GitSandip KaranjekarView Answer on Stackoverflow