如何查看某个提交的具体改动
查看提交的改动:git show <提交哈希> 显示完整 diff(信息+内容);只要统计用 --stat,只看文件名用 --name-only,看单行级变化加 --word-diff。
git show <提交哈希>:输出该提交的完整信息——作者、日期、提交信息、以及全部代码 diff。这是审查单个提交的标配命令。
常用变体
git show a1b2c3d # 完整 diff
git show --stat a1b2c3d # 只要统计摘要
git show --name-only a1b2c3d # 只要文件列表
git show --word-diff a1b2c3d # 行内变化高亮(改文案时好用)
git show a1b2c3d -- src/app.js # 只看某个文件的改动
对比任意两个提交
git diff a1b2c3d e4f5g6h # 两个提交间的差异
git diff a1b2c3d^! # ^! 语法 = 该提交自身的改动(同 show)
查看 merge 提交
git show 对合并提交默认只显示合并结果摘要,想看完整 diff:
git show --first-parent a1b2c3d # 相对主线父提交的 diff
git diff a1b2c3d^1 a1b2c3d # 等价显式写法
常见问题(FAQ)
Q:没有哈希怎么找提交?
git log --oneline 翻历史;git log -S"关键词" 按代码内容找;git reflog 找最近的 HEAD 移动记录。
Q:想看"这个文件在那个提交时长什么样"?
git show a1b2c3d:src/app.js 输出文件的完整内容(不是 diff)。
Q:IDE 里更方便吗?
VS Code(GitLens)和 JetBrains 的提交历史面板都提供图形化的提交审查视图,大改动看起来比终端 diff 省力。