简体   繁体   English

Git如何:拉分支之间的差异

[英]Git How to: pull diff between branches

I would like to download the files that are the difference between two branches into a local folder. 我想将两个分支之间的差异文件下载到本地文件夹中。 Is it possible with Git? Git有可能吗?

Given the files are only added to the source branch, they are not changed. 由于文件仅添加到源分支,因此它们不会更改。

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. 如果仅添加[文本]文件,则解析diff文件并将其拆分为单个文件将很简单。 (I'd say, it's a ruby script under 50 lines of code) (我想说,这是一个50行代码以下的ruby脚本)

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. 假设您现在在br2上,而br1在后面,则括号内的部分( git diff... )将为您提供两个文件头之间更改的文件列表。 The git archive command will export these files as they are on br2 (ie on your current head) to a tar file called export.tar inside a directory called exported/ . git archive命令会将这些文件在br2 (即您当前的头上) exported/到名为exported/的目录中的名为export.tar的tar文件中。

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. 该命令还将导出修改后的文件,但您声称没有任何文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM