How to split a branch after a certain commit?

I added a few commits to the end of the branch, but I decided that they would be better off in a separate function branch.

Now I can create a branch and revert the changes to the main branch, but this creates a messy history, and ideally I would like to clear it before pushing to the remote repository.

Is there a better way to go from:

ABCDE 

in

 ABC \ DE 

As if I am forked correctly in C in the first place?

+4
source share
3 answers

I don’t know why everyone wants to reinstall here. All you have to do is create a function branch in the current head, and then reset your wizard back to where you want:

 git branch feature git reset --hard HEAD~2 
+7
source
  • Create a new HEAD git checkout branch:

    git checkout master
    git checkout -b branch

    This creates a new branch that contains all of the master commits

  • Remove commits D and E from the wizard using interactive git rebase :

    git checkout master
    git rebase -i <SHA_A>

    In the editor that appears, delete lines with commits D and E
    If you have not changed the editor, this is Vim, so press j until you insert commit D into the line, then enter d d to delete this line. Same thing with the commit E line. When you're done, type : w q to close the editor.

Done!

A quick reference VIM map can be found here: http://tnerual.eriogerg.free.fr/vim.html

+1
source

I think you can check the commit ( git checkout sha ) and then from there from there ( git checkout -b newbranch ). I have not tested this.

EDIT : I just realized that you want to move the commit after that commit of the new branch. I believe you will want to learn git rebase .

0
source

All Articles