Reputation: 4131
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.
Upvotes: 7
Views: 9842
Reputation: 72745
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.
Upvotes: 8
Reputation: 230286
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)
Upvotes: 12