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.
How do I compare two different branches in my Git repository? Using git-diff you can compare two branches by viewing a diff between them, or you can use git-log to view a list of commits that comprise the difference between them. Compare two branches with git diff branch1.. branch2 .
Compare Branches in a Single Commandgit diff is a useful command that allows us to compare different types of git objects, such as files, commits, branches, and many more. This makes git diff a good choice when we need to compare the differences between two branches.
To compare your currently checked out branch with other branches using Visual Studio, you can utilize the branch picker hosted in the status bar and the Git changes tool window to choose any local or remote branch to compare with. Right click the branch you are targeting and select Compare with Current Branch.
How Do I Find the Difference Between Two Branches? For comparing two branches in Git, you simply run git diff <source-branch-name>.. <destination-branch-name> . Of course, you can replace the current branch name with HEAD.
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)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With