1

I am writing a shell script to automate code retrofit between two different Git branches. The requirement is I get a list of Git commits(which I have stored in a database table) from one branch and replay those changes on the other branch, and for that I am using Git Cherry-Pick command as below.

git checkout target_branch
<Sql command to get commit list> | xargs git cherry-pick

The above fails altogether if there are conflicts while picking any of the commits, and I need to implement the following logic using a seperate parameter as input to the script

-> if parameter value is Abort, list the files for which conflicts occured while cherry picking and then clean the repo(i am using git reset --merge for cleaning)
-> if parameter value is Overwrite, overwrite the conflicting files with the version of the commit hash

I have tried many options, but the only thing left is to create a dummy branch by cherry picking only those commits and then merge the dummy with target, but I don't know how to create a new branch by cherry picks only.

Please suggest a way.

Thanks. Kumarjit

1 Answers1

0

I don't know how to create a new branch by cherry picks only.

Considering a cherry-pick is applied on the current branch, you could:

  • first create the new branch

    git checkout -b aNewBranch
    
  • the apply your cherry-picks as usual.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Which branch should i create the new branch from? If its the target branch, would it be same as cherry picking into the target? –  Oct 23 '18 at 08:39