Git 如何:在分支之间提取差异

发布于 2024-12-21 04:13:21 字数 69 浏览 1 评论 0原文

我想将两个分支之间的差异文件下载到本地文件夹中。用Git可以吗?

鉴于文件仅添加到源分支,因此它们不会更改。

I would like to download the files that are the difference between two branches into a local folder. Is it possible with Git?

Given the files are only added to the source branch, they are not changed.

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

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

发布评论

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

评论(2

凉月流沐 2024-12-28 04:13:21

您可以通过以下几行获取分支之间的所有更改:

git diff origin/master origin/develop > my_diff.diff

如果您只添加 [text] 文件,那么解析 diff 文件并将其分解为单独的文件将是微不足道的。 (我想说,这是一个不到 50 行代码的 ruby​​ 脚本)

You can get all changes between branches with something around these lines:

git diff origin/master origin/develop > my_diff.diff

If you only add [text] files, then it would be trivial to parse the diff file and break it into individual files. (I'd say, it's a ruby script under 50 lines of code)

[旋木] 2024-12-28 04:13:21
git archive --format=tar --prefix="exported/" -o export.tar br2 $(git diff --name-only br1 br2)

假设您现在位于 br2 上,并且 br1 落后于它,括号内的部分 (git diff... ) 将给出您在两个头之间更改的文件列表。 git archive 命令会将这些文件在 br2(即当前头)上的文件导出到一个名为 export.tar 的 tar 文件中。名为 exported/ 的目录。

这假设(就像您在问题中所述)您仅添加了新文件并且添加了所有差异。该命令还将导出修改后的文件,但您声称没有任何文件。

git archive --format=tar --prefix="exported/" -o export.tar br2 $(git diff --name-only br1 br2)

Assuming you're on br2 right now and br1 is lagging behind it, the part inside the brackets (git diff... )will give you the list of the files changed between the two heads. The git archive command will export these files as they are on br2 (i.e. on your current head) to a tar file called export.tar inside a directory called exported/.

This assumes (like you stated in your question) that you've only added new files and that all the diffs are adds. The command will also export modified files but you claim not to have any.

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