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

查看:163
本文介绍了导出/归档仅在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。使用 - 仅限名称,您可以查找文件:

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天全站免登陆