[git] How to 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.

This question is related to git version-control diff git-diff

The answer is


First get the commit ID using,

git log #to list all

Or

git log -p -1 #last one commit id

Copy commit id.

Now we use two methods to list changes from a specific commit,

Method 1:

git diff commit_id^! #commit id something like this 1c6a6000asad012

Method 2:

git show commit_id
For example: git show 1c6a600a

In case of checking the source change in a graphical view,

$gitk (Mention your commit id here)

for example:

$gitk HEAD~1 

This command will get you the Git parent commit-hash:

git log -n 2 <commit-hash>

After that git diff-tool <commit-hash> <parent-commit-hash>

Example:

bonnie@bonnie ~/ $ git log -n 2 7f65b9a9d3820525766fcba285b3c678e889fe3

commit 7f65b9a9d3820525766fcba285b3c678e889fe3b
Author: souparno <[email protected]>
Date:   Mon Jul 25 13:17:07 2016 +0530

CSS changed to maintain the aspect ratio of the channel logos and to fit them properly.

commit c3a61f17e14e2b80cf64b172a45f1b4826ee291f
Author: souparno <[email protected]>
Date:   Mon Jul 25 11:28:09 2016 +0530

The ratio of the height to width of the channel images are maintained.

After this

git difftool 7f65b9a9d3820525766fcba285b3c678e889fe3b c3a61f17e14e2b80cf64b172a45f1b4826ee291f

You can also try this easy way:

git show <COMMIT>

git show <commit_sha>

This will show you just what's in that commit. I think you can do a range it by just putting a space between two commit shas.

git show <beginning_sha> <ending_sha>

which is pretty helpful if you're rebasing often because your feature logs will all be in a row.


You could use git diff HEAD HEAD^1 to see the diff with the parent commit.

If you only want to see the list of files, add the --stat option.


For checking complete changes:

  git diff <commit_Id_1> <commit_Id_2>

For checking only the changed/added/deleted files:

  git diff <commit_Id_1> <commit_Id_2> --name-only

NOTE: For checking diff without commit in between, you don't need to put the commit ids.


It is also possible to review changes between two commits for a specific file.

git diff <commit_Id_1> <commit_Id_2> some_dir/file.txt

I'm running Git version 2.6.1.windows.1 on Windows 10, so I needed a slight modification to Nevik's answer (tilde instead of caret):

git diff COMMIT~ COMMIT

Another option is to quote the caret:

git diff "COMMIT^" COMMIT

The following seems to do the job; I use it to show what has been brought in by a merge.

git whatchanged -m -n 1 -p <SHA-1 hash of merge commit>

The following code will show the current commit

git show HEAD

I like the below command to compare a specific commit and its last commit:

git diff <commit-hash>^-

Example:

git diff cd1b3f485^-

To see author and time by commit use git show COMMIT. Which will result in something like this:

commit 13414df70354678b1b9304ebe4b6d204810f867e
Merge: a2a2894 3a1ba8f
Author: You <[email protected]>
Date:   Fri Jul 24 17:46:42 2015 -0700

     Merge remote-tracking branch 'origin/your-feature'

If you want to see which files had been changed, run the following with the values from the Merge line above git diff --stat a2a2894 3a1ba8f.

If you want to see the actual diff, run git --stat a2a2894 3a1ba8f


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.


git difftool COMMIT^ <commit hash>

is also possible if you have configured your difftool.

See here how to configure difftool Or the manual page here

Additionally you can use git diff-tree --no-commit-id --name-only -r <commit hash> to see which files been changed/committed in a give commit hash


Another possibility:

git log -p COMMIT -1

From the man page for git-diff(1):

git diff [options] [<commit>] [--] [<path>…]
git diff [options] --cached [<commit>] [--] [<path>…]
git diff [options] <commit> <commit> [--] [<path>…]
git diff [options] <blob> <blob>
git diff [options] [--no-index] [--] <path> <path>

Use the 3rd one in the middle:

git diff [options] <parent-commit> <commit>

Also from the same man page, at the bottom, in the Examples section:

$ git diff HEAD^ HEAD      <3>

Compare the version before the last commit and the last commit.

Admittedly it's worded a little confusingly, it would be less confusing as

Compare the most recent commit with the commit before it.


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


If you just want to see the changes in the latest commit, simply git show will give you that.


git show shows the changes made in the most recent commit.

Equivalent to git show HEAD.

git show HEAD~1 takes you back 1 commit.


Examples related to git

Does the target directory for a git clone have to match the repo name? Git fatal: protocol 'https' is not supported Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) git clone: Authentication failed for <URL> destination path already exists and is not an empty directory SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443 GitLab remote: HTTP Basic: Access denied and fatal Authentication How can I switch to another branch in git? VS 2017 Git Local Commit DB.lock error on every commit How to remove an unpushed outgoing commit in Visual Studio?

Examples related to version-control

How can I switch to another branch in git? Do I commit the package-lock.json file created by npm 5? Project vs Repository in GitHub Remove a modified file from pull request Git push: "fatal 'origin' does not appear to be a git repository - fatal Could not read from remote repository." Git: How to squash all commits on branch git: updates were rejected because the remote contains work that you do not have locally Sourcetree - undo unpushed commits Cannot checkout, file is unmerged Git diff between current branch and master but not including unmerged master commits

Examples related to diff

Create patch or diff file from git repository and apply it to another different git repository Comparing the contents of two files in Sublime Text Git diff between current branch and master but not including unmerged master commits Fast way of finding lines in one file that are not in another? Python - difference between two strings How to see the changes in a Git commit? unix diff side-to-side results? Find the files existing in one directory but not in the other git diff between two different files How to get the difference (only additions) between two files in linux

Examples related to git-diff

How to show uncommitted changes in Git and some Git diffs in detail Git list of staged files Create patch or diff file from git repository and apply it to another different git repository There isn't anything to compare. Nothing to compare, branches are entirely different commit histories git: diff between file in local repo and origin Git diff between current branch and master but not including unmerged master commits How to Diff between local uncommitted changes and origin How to see the changes in a Git commit? How do you take a git diff file, and apply it to a local branch that is a copy of the same repository? git diff file against its last change