GIT: merge two branches into a new one without dependencies in Gerrit
I have two branches in my local repo: branch_1 and branch_2, each is based on the same commit A and contains several commits (heads are A1 and A2 correspondingly).
I pushed both of A1 and A2 to Gerrit master branch and have two separate reviews.
Then, I abandoned them.
Now I need to create a new local branch branch_3 based on A and containing changes from both A1 and A2 into A3. I did:
git checkout -b branch_3 origin/master
git merge branch_1 branch_2
I have got a commit A3 that I need and pushed it to Gerrit.
A third review was created, but it depended on two previous abandoned commits, therefore I cannot submit it.
Is there any way to merge two branches into one commit A3 so that it depends on only A but not A1 and A2?
2 Solutions collect form web for “GIT: merge two branches into a new one without dependencies in Gerrit”
approach 1: try rebase the branch which contains A3 onto
approach 2: checkout a clean branch, cherry-pick commit A3, and push again:
git checkout -b feature --track origin/master
git cherry-pick A3
git push origin HEAD:refs/for/master
Option ‘-n’ should be used for cherry-pick for each necessary commit:
git checkout A git cherry-pick -n A1 git cherry-pick -n A2 git commit
A newly created commit A3 is the expected one.