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?
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.
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.
You can run:
git branch -f A 6
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With