当我执行gitdiffCOMMIT时,我看到了提交和HEAD之间的变化(据我所知),但我希望看到单个提交所做的变化。

我还没有在diff/log上找到任何明显的选项来提供输出。


当前回答

检查文件更改的更简单方法(示例)

# 1. Checkout a branch and see the list of commits
git log --oneline -5

# > Output
9b9b1f8 (HEAD -> master) Updated ABC
d58e5da chore: Added files
5a4aa2c chore: Added my pipeline
bb2b0b7 feat: Added ABC
473f711 feat: Added ZYX
# 2. Pick a commit hash and check which files were modified
git show --stat --oneline d58e5da

# > Output
d58e5da chore: Added versioning files
 Someabcfile                            | 18 ++++++++++++++++++
 myfolder/file.py                       | 19 +++++++++++++++++++
 myfolder/file.js                       |  7 +++++++
 myfolder/file.txt                      |  1 +
 4 files changed, 45 insertions(+)
# 3. Pick a file to check the differences
git show d58e5da myfolder12/file.py

或者,从列表中检查一次提交中的所有文件差异:

git show d58e5da

其他回答

我通常会:

git diff HEAD~1

显示有关上次提交的更改。如果您有更多的提交,只需将数字1增加到您希望看到的提交差异。

检查文件更改的更简单方法(示例)

# 1. Checkout a branch and see the list of commits
git log --oneline -5

# > Output
9b9b1f8 (HEAD -> master) Updated ABC
d58e5da chore: Added files
5a4aa2c chore: Added my pipeline
bb2b0b7 feat: Added ABC
473f711 feat: Added ZYX
# 2. Pick a commit hash and check which files were modified
git show --stat --oneline d58e5da

# > Output
d58e5da chore: Added versioning files
 Someabcfile                            | 18 ++++++++++++++++++
 myfolder/file.py                       | 19 +++++++++++++++++++
 myfolder/file.js                       |  7 +++++++
 myfolder/file.txt                      |  1 +
 4 files changed, 45 insertions(+)
# 3. Pick a file to check the differences
git show d58e5da myfolder12/file.py

或者,从列表中检查一次提交中的所有文件差异:

git show d58e5da

我在windows 10上运行的是Git 2.6.1.windows.1版本,所以我需要对Nevik的答案稍作修改(用波浪号代替插入符号):

git diff COMMIT~ COMMIT

另一个选项是引用插入符号:

git diff "COMMIT^" COMMIT

首先使用,

git log #to list all

Or

git log -p -1 #last one commit id

复制提交id。

现在我们使用两种方法列出特定提交的更改,

方法1:

git diff commit_id ^#提交id类似于1c6a6000asad012

方法2:

git show commit_id
For example: git show 1c6a600a

以下内容似乎可以完成任务:;我用它来显示合并带来了什么。

git whatchanged -m -n 1 -p <SHA-1 hash of merge commit>