如何在Git中比较当前工作区与上一个提交?

huangapple go评论85阅读模式
英文:

How to compare current workingspace with previous commit in git?

问题

有时候我在修复错误时,需要将当前存储库与特定提交进行比较,以查看哪些文件正在更改以及整体功能。

在VSCode中使用Git History扩展,我只能一次比较一个文件与特定提交,但我想查看整个存储库的更改。目前,我会执行软重置到我想要比较的提交。

git reset --soft 13dbd96

在Git或第三方VSCode扩展中是否有其他更高效的使用方法?

英文:

Sometimes when I fix bugs, I need to compare current repo with a specific commit to see which files are being changed and overall features.

Using git history extension in vscode, I can only compare one file at a time with a specific commit but I want to view the entire repo changes. Currently, I soft reset to the commit I want to compare.

git reset --soft 13dbd96

Is there other ways in git or third party vscode extensions to use that is more efficient?

答案1

得分: 0

使用git diff命令进行比较。正如@evolutionxbox建议的,你可以使用git diff 13dbd96来查看示例。你还可以通过查看不同blob的路径来进行导航。

例如,你可以使用命令git diff HEAD~2来查看当前版本与HEAD~2版本之间的所有差异。

另一件事情:在多次更改HEAD的位置之前,git reset可以是查看版本之间文件变化列表的一个明智方式,但在改变HEAD位置之前,你可能希望确保已经储藏了你的更改。你不想意外执行硬重置然后丢失你最近的更改。

英文:

Use the git diff command to compare. As @evolutionxbox suggested, you could use git diff 13dbd96 for your example. You can also make use of navigations by looking at the paths to your different blobs.

For instance, you can see all differences between your current version and the version at HEAD~2 by using the command, git diff HEAD~2.

Another thing: git reset can be a smart way to look at lists of files that changed between versions, but you'll probably want to make sure you have stashed your changes before changing the position of the HEAD a bunch of times. You don't want to accidentally do a hard reset and then lose your most recent changes.

huangapple
  • 本文由 发表于 2023年8月11日 00:20:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/76877609.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定