Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I see the changes in a Git commit?

When I do git diff COMMIT I see the changes between that commit and HEAD (as far as I know), but I would like to see the changes that were made by that single commit.

I haven't found any obvious options on diff / log that will give me that output.

like image 993
laktak Avatar asked Jul 10 '13 06:07

laktak


People also ask

How do you see the details of a commit?

`git log` command is used to view the commit history and display the necessary information of the git repository. This command displays the latest git commits information in chronological order, and the last commit will be displayed first.

Which command show the changes between commits?

The git diff command is commonly used to get the unstaged changes between the index and working directory. It can be also used to show changes between two arbitrary commits. To view the changes between two commits, you can provide the commit hashes.

Which git command will show the changes since the last commit?

By default git diff will show you any uncommitted changes since the last commit.


2 Answers

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.)

like image 166
Nevik Rehnel Avatar answered Sep 28 '22 04:09

Nevik Rehnel


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?".

like image 39
VonC Avatar answered Sep 28 '22 06:09

VonC