问题描述
我们需要找到在提交中修改的文件,以进行某些操作。
该笔记将记录:在 Git 中,如何获取在提交中被修改的文件。
解决方案
获取_在某次提交中_修改的文件:
# git diff-tree --no-commit-id --name-only -r 35285f296b68617c0198e770a6a5ca0a7b2db6e8 src/com/k4nz/blog/BlogStorage.groovy
使用 git log 命令查看:
# git log --name-status commit 7723f2548c26655be9f282ba7a317c9192073c05 (grafted, HEAD -> master, origin/master, origin/HEAD) Author: Sandeep Somavarapu <sasomava@microsoft.com> Date: Sat Nov 28 10:11:01 2020 +0100 Fix #109406 A .devcontainer/README.md A .devcontainer/cache/.gitignore A .devcontainer/cache/before-cache.sh ...
仅显示修改的文件:
# git log --format=format: --name-only .devcontainer/README.md .devcontainer/cache/.gitignore .devcontainer/cache/before-cache.sh .devcontainer/cache/build-cache-image.sh .devcontainer/cache/cache-diff.sh .devcontainer/cache/cache.Dockerfile .devcontainer/cache/restore-diff.sh .devcontainer/devcontainer.json ...
参考文献
github – Getting a commit count for each file in a git repository – Stack Overflow
How to find the number of files changed from one commit to another in git – Stack Overflow
git – Which Jenkins Command to Get the List of Changed Files – Stack Overflow
git – How to list all the files in a commit? – Stack Overflow