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.

  • How to recover a merge commit after a rebase on the same commit?
  • Creating a remote inside a directory of remotes
  • How to track a remote git branch?
  • Git: How to merge a small, but very old branch?
  • Git: merge to master, then push back to all branches
  • head detached at commit. Need to put on master branch
  • 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?

  • can't commit to git / github
  • Deploying Hexo on Azure.. not sure what i'm missing
  • Adding Git repository to Perforce depot
  • With git how can i merge a repository that has already been merged?
  • Difference between 'git log origin/master' vs 'git log origin/master..'
  • Github enforce --no-ff when merging
  • 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 origin/master

    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.

    Git Baby is a git and github fan, let's start git clone.