Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a patch with every commit in log output

Tags:

git

I have a situation similar to this question. Currently this command shows me perfectly all the commits I need:

git log --cherry-pick --oneline --no-merges --left-only branchB...branchA

Now, I want to create a patch file with every one of the commits displayed in the above command. How can I do it?

like image 770
odiseo Avatar asked Oct 31 '22 15:10

odiseo


1 Answers

Try this. I hope it's not too late.

NUM=1
for commit in $(git log --cherry-pick --no-merges --left-only branchB...branchA --reverse --pretty=tformat:"%H")
do
  git format-patch -1 $commit --start-number $NUM
  ((NUM++))
done

--reverse forces git-log to push results in reversed order - from the earliest one to the latest one, "%H" it's format containing only commit sha1 hash. Hashes are being provided as a single (-1) commits to create patch from. --start-number with incrementing value causes creation of patch files in right order.

like image 57
mazharenko Avatar answered Nov 15 '22 05:11

mazharenko