Exporting / Archiving changed files only in Git

岁酱吖の 提交于 2019-12-17 17:39:06

问题


Is there a simple way to export / archive only the changed files from a given commit or series of commits in git? I can't seem to find clear instructions to do this (and I'm new to Linux/Git).

I am using msysgit, and for the most part I'm fine with deploying entire repositories but in many cases it is much more efficient to deploy small fixes a few files at a time.

Pushing/pulling/installing git on the remote servers isn't really an option as my level of access varies between projects and clients.

Is there a straight-forward way to (rough guess):

pipe 'diff --names-only' to 'git-archive'? 

回答1:


I don't think there's any need to involve git-archive. Using --name-only, you could tar up the files:

tar czf new-files.tar.gz `git diff --name-only [diff options]`

Since you're new to Linux, this might need some explanation:

The backticks in the command line cause the shell to first execute the command within the backticks, then substitute the output of that command into the command line of tar. So the git diff is run first, which generates a list of filenames, one on each line. The newlines are collapsed to spaces and the whole list of files is placed on the tar command line. Then tar is run to create the given archive. Note that this can generate quite long command lines, so if you have a very large number of changed files you may need a different technique.



来源:https://stackoverflow.com/questions/1678032/exporting-archiving-changed-files-only-in-git

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!