Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save git commits on a branch to the file

Tags:

git

Given the local branch (say 'test') - is it possible use some git magic to save commits on this branch to a file that I can send to the other developer who can then apply these commits to his branch? I know that there is a way to save every commit on a branch to the file, but not sure if it can be done for just commits on a local branch.

E.g. say master branch has commits 'a', 'b' and 'c' and my test branch has been created on 'c' and has commits 'd' and 'e':

 + (branch:master)
 |
 * commit:'a'
 |
 * commit:'b'
 |
 * commit:'c'
 |  \
...  + (branch:test)
     |
     * commit:'d'
     |
     * commit:'e' 
     x

So after generating that diff between 'test' and 'master' branches I want to have just 'd' and 'e' commits in that diff. So the other developer can also create his own test branch from master, apply my diff and have commits 'd' and 'e' on his branch.

I know that this can be achieved by pushing changes to the remote branch, but for some reasons I would like to avoid doing that and yes, I know branches are cheap, but believe me I have good reasons to not to push these changes to the remote branch.

like image 635
Alex Avatar asked Nov 17 '25 19:11

Alex


1 Answers

in your test branch do

git format-patch master --stdout > patch.diff

When applying

git am < patch.diff
like image 200
usha Avatar answered Nov 19 '25 09:11

usha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!