简体   繁体   中英

Diff between last commit and commit before last commit?

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?

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:
Configuring diff tool with.gitconfig

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM