I have branches A and B in git. Here I am cherry picking changes from branch A to branch B. For this I have created a tag in branch A and made 10 different commits on top of it. The first commit has been tagged in branch A.
Git cherry pick command takes commit hashes as input.
For this I have a list of commit hashes (SHA) starting from a tag (in branch A) in a variable like this.
Checkout branch A
commithash="$(/usr/bin/git log --boundary --pretty=oneline ${tag_name}.. | sed -e 's/- //'| cut -d ' ' -f 1)"
echo $commithash ---gives spaces delimited commit hashes below.
3f899d3eebce23ce6a1efd3b73ea0b328c8cf3e1 2180e9e8a0a73a5313e70317a20360e3314b2568 f001ad3d03b6a4231d370a3b389d6edbd14db73b 66049c094a0780df7a518ba75d677213168e5211 3a6e53426e85f36b8fc3e19586c18d1ee0abf31b 0b2698bf67ea0c29f0e76fe110a0b89ccbfdecd2 8aed2c998dcd38ac5e01be5d1004d7130b1b2458 07a65386ad8883bf5f774541461cce0779d8b0d2 b57d0d1cea1cf8a151f1244c30b8f08eb7583926
I now switch to branch B
For each commit hash in that variable I want to run the command.
git cherry-pick --strategy-option theirs $(for-each-commit-sha)
When running the command it is successful except for a below scenario where it fails.
A. if the output for cherry pick command has the below output the script fails and none of the file are cherry picked.
error: could not apply 34h5432.. adding dev text for cc in file
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'
Below is the output of:
git status
On branch B
You are currently cherry-picking commit 34h5432...
(fix conflicts and run "git cherry-pick --continue")
(use "git cherry-pick --abort" to cancel the cherry-pick operation)
Unmerged paths:
(use "git add/rm <file>..." as appropriate to mark resolution)
deleted by us: cc.txt
In this scenario I want to run git add cc.txt or issue a git add for whatever is mentioned after "deleted by us: "
git add cc.txt
git commit -m "adding file"
Then continue cherry pick for rest of the commit hashes in the list until the last.
The cherry pick needs to be done from last commit sha to first. In this case start with b57d0d1cea1cf8a151f1244c30b8f08eb7583926
and ends with
3f899d3eebce23ce6a1efd3b73ea0b328c8cf3e1
How can I do that ?
commithash="$(/usr/bin/git log --boundary --pretty=oneline ${tag_name}.. | sed -e 's/- //'| cut -d ' ' -f 1)"