You can use git rebase -i --root
to rebase everything starting with the initial commit.
Let's say you had 11 commits that looked something like this:
* cf0bc41 - (HEAD, master) Faun: Eleven (2 seconds ago)
* b32d8cc - Faun: Ten (2 seconds ago)
* f789e49 - Faun: Nine (2 seconds ago)
* 780435e - Faun: Eight (2 seconds ago)
* 3c6b084 - Faun: Seven (2 seconds ago)
* fecce89 - Faun: Six (2 seconds ago)
* 0433dbe - Faun: Five (2 seconds ago)
* 8002cb7 - Faun: Four (2 seconds ago)
* 3439445 - Faun: Three (2 seconds ago)
* 38181f1 - Faun: Two (2 seconds ago)
* 9373809 - Faun: One (2 seconds ago)
If you want to remove the first 10 commits, just run git rebase -i --root
, which will open something like the following in your editor:
pick 9373809 One
pick 38181f1 Two
pick 3439445 Three
pick 8002cb7 Four
pick 0433dbe Five
pick fecce89 Six
pick 3c6b084 Seven
pick 780435e Eight
pick f789e49 Nine
pick b32d8cc Ten
pick cf0bc41 Eleven
# Rebase cf0bc41 onto 0bd34c4
You can simply delete the lines of the commits that you want to delete. However, that will probably result in a conflict, as later commits most likely modified files you introduced with one of your earlier commits.
Also be aware that running this command will rewrite the SHAs for all commits, which might also cause you problems.
It's probably better to squash or fixup those initial commits. Leave the first one alone and change the word pick
to squash
or fixup
. See the comments at the bottom of the interactive rebase for more information.
For example if you edit the interactive rebase look like this:
pick 9373809 One
fixup 38181f1 Two
fixup 3439445 Three
fixup 8002cb7 Four
fixup 0433dbe Five
fixup fecce89 Six
fixup 3c6b084 Seven
fixup 780435e Eight
fixup f789e49 Nine
fixup b32d8cc Ten
pick cf0bc41 Eleven
You'll end up with this git history:
* f8980bc - (HEAD, master) Faun: Eleven (0 seconds ago)
* 3d300e9 - Faun: One (0 seconds ago)