仅在 Git 中导出/存档更改的文件
有没有一种简单的方法可以仅导出/存档 git 中给定提交或一系列提交中更改的文件?我似乎找不到明确的说明来执行此操作(而且我是 Linux/Git 的新手)。
我正在使用 msysgit,在大多数情况下,我可以很好地部署整个存储库,但在许多情况下,一次部署几个文件的小修复会更有效。
在远程服务器上推送/拉动/安装 git 并不是真正的选择,因为我的访问级别因项目和客户端而异。
有没有一种直接的方法(粗略猜测):
pipe 'diff --names-only' to 'git-archive'?
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'?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为没有必要涉及 git-archive。使用
--name-only
,您可以压缩文件:由于您是 Linux 新手,这可能需要一些解释:
命令行中的反引号导致 shell 首先执行以下命令:反引号,然后将该命令的输出替换到
tar
的命令行中。因此,首先运行 git diff,它会生成一个文件名列表,每行一个。换行符被折叠为空格,整个文件列表被放置在tar
命令行上。然后运行 tar
来创建给定的存档。请注意,这可能会生成相当长的命令行,因此如果您有大量更改的文件,您可能需要不同的技术。I don't think there's any need to involve git-archive. Using
--name-only
, you could tar up the files: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 thegit 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 thetar
command line. Thentar
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.