I have a project with a long git history. I want to open-source it, but there's a long section at the beginning that I want to remove first.
* ddfe660 - (HEAD, origin/master)
|
| (many hundreds of commits, including merges)
|
* 420b801 - (the intended beginning of the new history)
* 00a3516 - (the most recent commit I want squashed out)
|
| (many hundreds of commits, including merges)
|
* 6b6fc1e - first commit
I pseudo-git, I want git squash 6b6fc1e..420b801
. That is, I want a new first commit that is the sum
of that whole range, with the commit message from 420b801
.
Here are some things I've tried:
- Interactive rebase:
git rebase -i 6b6fc1e
, usingfixup
for all of6b6fc1e..00a3516
andsquash
for420b801
. This failed as soon as I got to a merge commit in the first range because I don't know how to resolve those conflicts. - Interactive rebase with
--preserve-merge
:git rebase -p -i 6b6fc1e
. This had the same problem. git rebase -p --root 420b801
. This had the same problem.- Fiddling with
--root
:git checkout 6b6fc1e && git reset --soft 420b801 && git commit --amend
, as suggested here. That didn't seem to remove any of the commits in the range I want to squash.
@wagenet part one worked great:
That left me with a new tree with exactly one commit containing exactly what I want!
Then I tried part two:
I can't exactly explain what that did, but it seemed to have made
master
point to just the one-commit treetmp
.Another attempt:
This had the merge-conflict problems.
But a third seemed to go better:
I need to do some verification, but this seems to have worked!