Search code examples
gitrebase

git: rebase between init commit to specified commit


How do I rebase between commits:

Lets say I want to rebase between init and commit 3 (squash these commits together)

Lets say i have

commit 5
commit 4
commit 3
commit 2
commit 1
commit init

If I do

git rebase -i commit 3 

I get this:

pick commit 3
pick commit 4
pick commit 5

Then when i do

squash commit 3
pick commit 4
pick commit 5

And I execute the action, I get this:

commit 3
commit 2
commit 1
commit init

Instead of what i want.

How do I squash commit init<---->commit 3, instead of commit 3<----->commit 5

Thanks in advance.

Jenia.


Solution

  • Do

    git rebase -i --root
    

    Git will drop you into an editor with

    pick commitinit
    pick commit2
    pick commit3
    pick commit4
    pick commit5
    

    then just change it to

    pick commitinit
    squash commit2
    squash commit3
    pick commit4
    pick commit5