Re: how to squash two commits into only one
- From
- Dirk Süsserott <newsletter@dirk.my1.cc>
- Date
- Mar 30, 2011, 19:22 UTC
- Message-ID
- <4D9382ED.4090806@dirk.my1.cc>
- In-Reply-To
- <7v1v1psrvr.fsf@alter.siamese.dyndns.org>
Am 29.03.2011 20:28 schrieb Junio C Hamano:
Show 11 quoted lines
> Nguyen Thai Ngoc Duy<pclouds@gmail.com> writes: > >>> Actually, that should be: `git reset --soft HEAD^; git commit --amend`. >> >> "git rebase --root" does not seem a bad idea though. > > The lack of this did't annoy me enough (one woudln't have to deal with > root commits too often) so I wouldn't bother implementing it myself, but > "git rebase --root" especially with "-i" would be a nice addition. > > i.e. well written and explained patches welcome.
Lynn, this won't help you right now, but perhaps in the future: When I create a new repo, the first thing I do is creating an empty commit, like so:
git init my_repo cd my_repo git commit --allow-empty -m "Initial commit (empty)"
This creates an empty root commit which is helpful not only in your case.
Another way to solve your problem would be to prepend that empty root commit to your repo afterwards. It's a bit weird, but it works -- at least if you don't have branches (except for "master").
git checkout --orphan new_master (1) git rm -rf . (2) git commit --allow-empty -m "Initial commit (empty)" (3) git rebase new_master master (4) git branch -d new_master (5)
(1) creates a new branch 'new_master' which is totally independent
of any other branch in the repo, thus the option's name. But it
silently does a "git add .", i.e. it stages all files that were
checked out before issuing the command. See 'checkout' docs
for details.
(2) removes all the files staged in (1), so that you have a new
starting point which is really clean.
(3) creates the empty root commit on 'new_master'
(4) replays all changes of 'master' to 'new_master'. 'new_master'
then has three commits: the root commit and the two commits from
'master'
(5) removes the 'new_master' which is no longer needed.And NOW you can do your 'rebase -i <root_commit>' to squash your actual commits.
If you have more than one branch you would have to repeat step (4) with the other branches.
HTH, Dirk