How do I use 'git rebase -i' to rebase all changes in a branch?

后端 未结 8 1365
Happy的楠姐
Happy的楠姐 2020-12-12 20:36

Here\'s an example:

>git status
# On branch master
nothing to commit (working directory clean)
>git checkout -b test-branch
>vi test.c
>git add t         


        
8条回答
  •  孤城傲影
    2020-12-12 20:46

    Ok, I'm asuming the branch is called "feature" and it was branched from "master".

    There's this little git command called merge-base. It takes two commits and gives you the first common ancestor of both of those. So...

    git merge-base feature master
    

    ...will give you the first common ancestor of those two commits. Guess what happens when you pass that commit to git rebase -i, like...

    git rebase -i `git merge-base feature master`
    

    Interactive rebase from the first common ancestor of both master and feature branch. Profit! ;)

提交回复
热议问题