有时候看到一个 commit hash,只想先扫一眼它动了哪些文件,不一定马上展开完整 diff。git show --stat 会把提交信息和文件改动统计列出来,适合先判断范围。
环境:Git 2.30+。可以随便建个目录试:
mkdir git-show-stat-demo && cd git-show-stat-demo
git init
printf 'hello\n' > app.txt
git add app.txt
git commit -m 'init'
printf 'hello\nworld\n' > app.txt
mkdir docs
printf 'note\n' > docs/readme.md
git add app.txt docs/readme.md
git commit -m 'update app and docs'
git show --stat HEAD
如果只想更短一点,也可以:
git show --stat --oneline HEAD
我一般会先看这个,再决定要不要继续 git show HEAD -- app.txt 这种按文件展开。比一上来被大段 diff 糊脸轻松一点。