From: Tor Arntsen Date: Tue, 29 Mar 2011 08:50:57 GMT Subject: Re: how to squash two commits into only one Message-ID: In-Reply-To: On Tue, Mar 29, 2011 at 10:24, Lynn Lin wrote: > Thanks .However my case is like: > git log > 1 > 2 > > I want to squash 1 to 2,what's the commit I should specify with rebase -i That would be 3, i.e. rebase -i 3 That won't work if there are only two commits in total.. rebase needs a commit before the one you want to squash to. But in that case you would do 'git reset HEAD^1' (and end up with only commit 2, and 'M' for the modifications originally done in commit 1), 'git add' , 'git commit --amend', which is exctly what Henrik described earlier. There is a particular problem if you have this sequence: git log 1 2 3 4 5 (initial commit) and you want to squash 4 into 5.. there's no hash 6 to rebase -i to. There are several ways to do it, but what I do is something like this: git checkout 4 git checkout -b tmp git reset HEAD^1 git commit --amend git merge master git branch -M tmp master (<---- rename the tmp branch to 'master') the new master now has 4 and 5 squashed. I'm sure others on this list have different ways to do this, but it's the one method that looked obvious to me so that's what I did when I needed it (anyway it's more or less how I fixed historic commits in the past before I learned about 'rebase -i' .. well, rebase -i didn't even exist with the versions of Git I used back then anyway). -Tor