version control - How can I see the changes in a Git commit?

ID : 468

viewed : 134

Tags : gitversion-controldiffgit-diffgit





Top 5 Answer for version control - How can I see the changes in a Git commit?

vote vote

92

To see the diff for a particular COMMIT hash, where COMMIT is the hash of the commit:

git diff COMMIT~ COMMIT will show you the difference between that COMMIT's ancestor and the COMMIT. See the man pages for git diff for details about the command and gitrevisions about the ~ notation and its friends.

Alternatively, git show COMMIT will do something very similar. (The commit's data, including its diff - but not for merge commits.) See the git show manpage.

(also git diff COMMIT will show you the difference between that COMMIT and the head.)

vote vote

82

As mentioned in "Shorthand for diff of git commit with its parent?", you can also use git diff with:

git diff COMMIT^! 

or

git diff-tree -p COMMIT 

With git show, you would need (in order to focus on diff alone) to do:

git show --color --pretty=format:%b COMMIT 

The COMMIT parameter is a commit-ish:

A commit object or an object that can be recursively dereferenced to a commit object. The following are all commit-ishes: a commit object, a tag object that points to a commit object, a tag object that points to a tag object that points to a commit object, etc.

See gitrevision "SPECIFYING REVISIONS" to reference a commit-ish.
See also "What does tree-ish mean in Git?".

vote vote

70

You can also try this easy way:

git show <COMMIT> 
vote vote

69

git show shows the changes made in the most recent commit. It is equivalent to git show HEAD.

git show HEAD~1 takes you back one commit.

vote vote

59

I usually do:

git diff HEAD~1 

To show the changes regarding the last commit. If you have more commits just increase the number 1 to how many commits diff you want to see.

Top 3 video Explaining version control - How can I see the changes in a Git commit?







Related QUESTION?