简体   繁体   English

上次提交和上次提交之前的提交之间的区别?

[英]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?我只是git log查找最后一次提交的 ID,然后git diff last_commit_id prior_to_last_commit_id ,还是有更好的方法?

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命令:
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:如果您希望它在 IDE(如 Visual Studio Code)中打开,只需使用以下解决方案:
Configuring diff tool with.gitconfig 使用 .gitconfig 配置差异工具

Or for any other IDE see:或者对于任何其他 IDE,请参阅:
Configuring diff tool with.gitconfig 使用 .gitconfig 配置差异工具

Use git show to see the last commit使用git show查看最后一次提交

Since you're talking about seeing the contents of just one commit, I would use git show instead of git diff .由于您谈论的是仅查看一次提交的内容,因此我将使用git show而不是git diff

git show

will display the contents of HEAD , which is going to be the last commit since you just made it.将显示HEAD的内容,这将是您刚刚提交后的最后一次提交。 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使用git log -p查看最后几个提交

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为了稍微扩展您的用例,如果您想查看最后几个提交,最快的方法是-p切换到git log ,它显示日志一个又一个提交,但内容与git show

git log -p

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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