如何从 Git 导出所有更改/添加的文件?

发布于 2024-09-05 06:59:48 字数 353 浏览 8 评论 0原文

我对 Git 很陌生,有一个小问题。

在 SVN 中[这感觉就像阿尔伯特叔叔的《只有傻瓜和马》的故事......“在战争期间......”]当我想用我的最新更改更新生产站点时,我会这样做TSVN 中的差异并导出两个修订版之间所有更改/添加的文件。正如您可以想象的那样,之后很容易将这些文件发送到生产站点。

但是,我似乎无法在 Git 中找到“导出更改的文件”选项。我可以进行比较并查看更改,我可以获得文件列表,但实际上无法导出它们。有没有合理的方法来做到这一点?我错过了一些简单的事情吗?

只是为了再次澄清,我需要导出两个特定提交之间的所有更改。

提前致谢!

I am very new to Git and I have a slight problem.

In SVN [this feels like an Only Fools and Horses story by uncle Albert.."during the war..."] when I wanted to update a production site with my latest changes, I'd do a diff in TSVN and export all the changed/added files between two revisions. As you can imagine, it was easy to get those files to a production site afterwards.

However, it seems like I'm unable to find an "export changed files" option in Git. I can do a diff and see the changes, I can get a list of files, but I can't actually export them. Is there a reasonable way to do this? Am I missing something simple?

Just to clarify once again, I need to export all the changes between two specific commits.

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

人疚 2024-09-12 06:59:48

您想如何导出它们?你说你已经有了一份清单;你还想要什么? 来获取列表

git archive --output=<file> HEAD $(git diff --name-only ...)

tar -czf <file> $(git diff --name-only ...)

cp --parents $(git diff --name-only ...) <export-directory>

假设您正在使用 git diff --name-only ...类似的东西

?或者你甚至可以使用 diff 本身 - 它可以与 git apply 一起应用(我相信甚至可以使用 patch )。

How do you want to export them? You say you already have a list; what more do you want? Supposing you're getting your list with git diff --name-only ...

git archive --output=<file> HEAD $(git diff --name-only ...)

tar -czf <file> $(git diff --name-only ...)

cp --parents $(git diff --name-only ...) <export-directory>

Something like that?

Or you could even use the diff itself - it can be applied with git apply (or even patch, I believe).

情场扛把子 2024-09-12 06:59:48

借用此处,这是导出在工作区中修改的文件的另一种方法:

git diff --diff-filter=ACMRT --name-only HEAD | xargs tar -rf export.tar

如果需要将未跟踪的文件包含在差异中,您可能需要预先执行以下命令来添加它们:

git add *

[这适用于 Windows 中的 git-bash]

Borrowing from few of the answers in here, here is another way to export files that are modified in the workspace:

git diff --diff-filter=ACMRT --name-only HEAD | xargs tar -rf export.tar

You might need to execute the following beforehand to add untracked files, if you need to include them in the diff:

git add *

[This works in git-bash in Windows]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文