如何查看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. 当我执行git diff COMMIT
我看到了该提交和HEAD之间的变化(据我所知),但我希望看到该单个提交所做的更改。
I haven't found any obvious options on diff
/ log
that will give me that output. 我没有在diff
/ log
上找到任何明显的选项,它会给我输出。
#1楼
参考:https://stackoom.com/question/1Bh7u/如何查看Git提交中的更改
#2楼
To see the diff for a particular COMMIT
hash: 要查看特定COMMIT
哈希的差异:
git diff COMMIT~ COMMIT
will show you the difference between that COMMIT
's ancestor and the COMMIT
. git diff COMMIT~ COMMIT
将显示COMMIT
的祖先和COMMIT
之间的区别。 See the man pages for git diff for details about the command and gitrevisions about the ~
notation and its friends. 有关命令和gitrevisions有关~
符号及其朋友的详细信息,请参阅git diff的手册页。
Alternatively, git show COMMIT
will do something very similar. 或者, git show COMMIT
会做一些非常相似的事情。 (The commit's data, including its diff - but not for merge commits.) See the git show manpage . (提交的数据,包括它的差异 - 但不适用于合并提交。)请参阅git show联机帮助页 。
#3楼
As mentioned in " Shorthand for diff of git commit with its parent? ", you can also use git diff
with: 正如“ 使用其父级的git提交的差异的简写? ”中所提到的,你也可以使用git diff
:
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,你需要(为了专注于diff)来做:
git show --color --pretty=format:%b $COMMIT
The COMMIT
parameter is a commit-ish : COMMIT
参数是commit-ish :
A commit object or an object that can be recursively dereferenced to a commit object. 甲commit对象或一个对象可以被递归地解除引用到一个提交对象。 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. 以下是所有承诺,ishes:提交对象, 标签对象指向一个commit对象,指向一个指向commit对象等标签对象标签对象
See gitrevision "SPECIFYING REVISIONS" to reference a commit-ish. 请参阅gitrevision“SPECIFYING REVISIONS”以引用commit-ish。
See also " What does tree-ish mean in Git? ". 另请参阅“ Git中树的含义是什么? ”。
#4楼
From the man page for git-diff(1) : 从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: 使用中间的第3个:
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. 将最近的提交与之前的提交进行比较。
#5楼
git difftool COMMIT^ <commit hash>
is also possible if you have configured your difftool. 如果您配置了difftool,也可以使用。
See here how to configure difftool Or the manual page here 看到这里如何配置difftool或手动页面点击这里
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 另外,您可以使用git diff-tree --no-commit-id --name-only -r <commit hash>
来查看在给定提交哈希中更改/提交的文件
#6楼
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>
下一篇: Git 如何放弃所有本地修改