Home > Back-end >  Diff between last commit and commit before last commit?
Diff between last commit and commit before last commit?

Time:12-11

I just created a local commit, and I would like to see all the changes that were made in that local commit, so I would like to diff it against what it was prior to that commit. Do I just git log to find the IDs of the last commits, and then git diff last_commit_id prior_to_last_commit_id, or is there a better approach?

In addition, when I tried this command, it brought up some kind of terminal interactive tool where I have to press the down arrow to see the changes in a file. Is there a way to show this in an editor instead of in the terminal?

CodePudding user response:

The short answer is: Yes! You did it correctly.
To compare those commits you need to do the git diff command:
git diff commit_id_1 commit_id_2

Then what you are facing is the default diff tool which is used to compare the commits.
If you'd like it to be opened in a IDE like Visual Studio Code, just use this solution:
How to use Visual Studio Code as the default editor for Git MergeTool

Or for any other IDE see:
Configuring diff tool with .gitconfig

CodePudding user response:

Use git show to see the last commit

Since you're talking about seeing the contents of just one commit, I would use git show instead of git diff.

git show

will display the contents of HEAD, which is going to be the last commit since you just made it. It display the log message and the changes introduced by that commit.

To see the contents of any other commit, just specify it:

git show <sha1 or other commitish>

Use git log -p to see the last few commits

To extend your use case just a little bit, if you want to see the last few commits, the quickest way there is the -p switch to git log, which shows the log one commit after the other, but with the same contents that git show

git log -p
  •  Tags:  
  • git
  • Related