Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git: moving branch head

Tags:

git

I have two git branches, "A" and "B", and commits numbered 1 thru 8. My history looks like this

1 -> 2 -> 3 -> 4[A] -> 5 -> 6 -> 7 -> 8[B] 

I want to change it so my history looks like this:

1 -> 2 -> 3 -> 4 -> 5 -> 6[A] -> 7 -> 8[B] 

That is, I want to move the head of branch A from commit 4 to commit 6.

What commands do I use to do this?

like image 532
Andrew Tomazos Avatar asked Mar 18 '12 15:03

Andrew Tomazos


People also ask

What does git branch move do?

You can think of them as a way to request a brand new working directory, staging area, and project history. New commits are recorded in the history for the current branch, which results in a fork in the history of the project. The git branch command lets you create, list, rename, and delete branches.

How do I move the head to the latest commit?

We need to specify the HEAD or the relative reference of the head to the commit we want to move. We do this using git reset –hard HEAD^ which means resetting back to the commit before head, and git reset –hard HEAD~n, which means resetting back to the n commits before head.


1 Answers

You can run:

git branch -f A 6 
like image 199
Matthew Flaschen Avatar answered Sep 22 '22 09:09

Matthew Flaschen