仅在 Git 中导出/存档更改的文件 [英] Exporting / Archiving changed files only in Git

查看:47
本文介绍了仅在 Git 中导出/存档更改的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种简单的方法可以仅导出/存档来自给定提交或 git 中一系列提交的更改文件?我似乎找不到明确的说明来执行此操作(而且我是 Linux/Git 的新手).

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).

我正在使用 msysgit,在大多数情况下,我可以部署整个存储库,但在许多情况下,一次部署几个文件的小修复要高效得多.

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.

在远程服务器上推送/拉取/安装 git 并不是一个真正的选择,因为我的访问级别因项目和客户端而异.

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'? 

推荐答案

我认为没有必要涉及 git-archive.使用 --name-only,你可以压缩文件:

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]`

由于您是 Linux 新手,因此可能需要一些解释:

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

命令行中的反引号使shell首先执行反引号内的命令,然后将该命令的输出替换到tar的命令行中.所以 git diff 首先运行,它会生成一个文件名列表,每行一个.换行符折叠为空格,整个文件列表放在 tar 命令行上.然后运行 ​​tar 以创建给定的存档.请注意,这会生成很长的命令行,因此如果您有大量更改的文件,您可能需要不同的技术.

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.

这篇关于仅在 Git 中导出/存档更改的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆