Export only modified and added files with folder structure in Git
I would like to get a list of modified and added files in an specific commit so that I can export them and generate a package with the file structure.
The idea is to get the package and extract it on the server. For many reasons I can't create a hook to pull the repo automatically and the easiest way I have to keep the server updated is generating this package.
git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT $commit_id
git diff-tree -r $commit_id
:
Take a diff of the given commit to its parent(s) (including all subdirectories, not just the top directory).
--no-commit-id --name-only
:
Do not output the commit SHA1. Output only the names of the affected files instead of a full diff.
--diff-filter=ACMRT
:
Only show files added, copied, modified, renamed or that had their type changed (eg. file → symlink) in this commit. This leaves out deleted files.
git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT $commit_id | xargs tar -rf mytarfile.tar
Just to round this out, here is the command piped to tar. This exports the files into a tar archive.
Here is a one-line command that works on Windows 7. Run it from your repository's top-level folder.
for /f "usebackq tokens=*" %A in (`git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT HEAD~1 HEAD`) do echo FA|xcopy "%~fA" "C:git_changed_files%A"
上一篇: Python是否有包/模块管理系统?