Re: how to squash two commits into only one

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Mar 29, 2011 at 10:24, Lynn Lin <lynn.xin.lin@xxxxxxxxx> 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' <the
files changed>, '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
<add files>
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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]