当我执行gitdiffCOMMIT时,我看到了提交和HEAD之间的变化(据我所知),但我希望看到单个提交所做的变化。
我还没有在diff/log上找到任何明显的选项来提供输出。
当我执行gitdiffCOMMIT时,我看到了提交和HEAD之间的变化(据我所知),但我希望看到单个提交所做的变化。
我还没有在diff/log上找到任何明显的选项来提供输出。
当前回答
从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>
使用中间的第三个:
git diff [options] <parent-commit> <commit>
同样从同一手册页底部的示例部分:
$ git diff HEAD^ HEAD <3>
比较上次提交和上次提交之前的版本。
诚然,它的措辞有点混乱,但也不会那么混乱
将最近的提交与之前的提交进行比较。
其他回答
gitshow显示了最近一次提交中所做的更改。它相当于git show HEAD。
git show HEAD~1会让您返回一次提交。
另一种可能性:
git log -p COMMIT -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
如“gitcommit与其父级的差异的速记?”中所述,您也可以将gitdiff用于:
git diff COMMIT^!
or
git diff-tree -p COMMIT
使用gitshow,您需要(为了只关注diff):
git show --color --pretty=format:%b COMMIT
COMMIT参数是COMMIT-ish:
提交对象或可以递归地取消引用到提交对象的对象。以下是所有提交对象:提交对象、指向提交对象的标记对象、指向指向提交对象标记对象的标签对象等。
参见gitrevision“指定修订”以引用提交。另请参阅“tree-ish在Git中是什么意思?”。
您也可以尝试以下简单方法:
git show <COMMIT>