Home > Blockchain >  Git Head Points at Two Local Branches Roll One Back by a Commit
Git Head Points at Two Local Branches Roll One Back by a Commit

Time:01-21

I have a situation where HEAD points to two branches and branch configuration is as follows:

* 76ee9315 - (HEAD -> branch_A, branch_B) 
*   242bf88d - (origin/branch_A) Merge branch 'branch_A' into branch_B 
|\
| * c5e6b6b9 - (origin/branch_B) 

How can make it so the latest commit only belongs to branch_A, whereas branch_B is rolled back by one commit? I tried checking out branch_B and doing a hard reset by one commit. However, that wiped the commit from both branches, and I had to get if back via reflog.

CodePudding user response:

Simple

git branch -f branch_B 242bf88d

The trick is to understand that branches are just pointers to commits. This command is telling git hey, set branch_B pointer on commit 242bf88d.

As a side note, HEAD is not pointing to 2 branches. It's rather that you have branch_A and branch_B pointing to the same commit and HEAD is pointing to branch_A (as in, that is the branch that is checked out).

  •  Tags:  
  • git
  • Related