5

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?

Community
  • 1
  • 1
odiseo
  • 6,754
  • 2
  • 20
  • 21

1 Answers1

2

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.

mazharenko
  • 565
  • 5
  • 11
  • I had the same problem when was migrating to another repository and successfully created commit files. Unfortunately, I wasn't able to apply them. – mazharenko Apr 05 '16 at 13:21