2

I'm trying to get several commits from my dev branch into my uat branch using "git cherry-pick -n hash" and then use just one git commit/push to send them to uat.

Let's suppose I have 5 commits I want, so I checkout and pull my uat branch and starts to cherry-pick from dev. The first 4 cherry-picks are successful, but the 5th fails with merge conflicts. How do I return to the previous state (after the 4th "git cherry-pick -n 4th_hash" ?

"git reset --merge" undo all changes (including the first 4 ones that I want). "git cherry-pick --abort" says that there is no cherry-pick in progress.

Is there some way to accomplish this? I'm trying to create a bash script to do it automatically.

1 Answers1

0

I am not sure how you want to do it automatically in a script if you have conflicts. But regardless to it. If you want to save previous state I suggest you remove the -n flag. So perform:

git cherry-pick <hash>

For each of the commits you want, and once you done squash them together.

git reset --soft HEAD~5 
git commit

Where 5 is the number of cherry-picks you just did. So it can work just the same with a script.

Igal S.
  • 13,146
  • 5
  • 30
  • 48
  • Thanks Igal. I'll try it. – Emerson Takahashi Dec 08 '15 at 13:31
  • I'm creating a Jenkins job that will try to do what is possible automatically, in my example, cherry-pick the first 4 commits, then commit/push it to uat and send an email to someone telling the the fifth commit has merge conflicts that needs to be solved. – Emerson Takahashi Dec 08 '15 at 13:40