tags:

views:

112

answers:

2

Hi,

I am trying to merge 2 commits into 1. So I follow this:

http://www.gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html

I did $ git rebase --interactive HEAD~2 It opens an editor I change 'pick' to 'squash' Save the editor But i get 'Cannot 'squash' without a previous commit'

so what can I do to recover?

When I do ' git rebase --interactive HEAD~2 Interactive rebase already started'

When I do '$ git rebase --continue Cannot 'squash' without a previous commit'

Thank you.

+2  A: 

you can cancel the rebase with

git rebase --abort

and when you run the interactive rebase command again the 'squash; commit must be below the pick commit in the list

Leom Burke
+2  A: 

Get back to where you started with

$ git rebase --abort

Say your history is

$ git log --pretty=oneline
a931ac7c808e2471b22b5bd20f0cad046b1c5d0d c
b76d157d507e819d7511132bdb5a80dd421d854f b
df239176e1a2ffac927d8b496ea00d5488481db5 a

That is, a was the first commit, then b, and finally c.

Running git rebase --interactive HEAD~2 gives you an editor with

pick b76d157 b
pick a931ac7 c

# Rebase df23917..a931ac7 onto df23917
#
# Commands:
#  p, pick = use commit
#  r, reword = use commit, but edit the commit message
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#  f, fixup = like "squash", but discard this commit's log message
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#

Changing b's pick to squash will result in the error you saw, but if instead you squash c into b by changing the text to

pick b76d157 b
s a931ac7 c

and save-quitting your editor, you'll get another editor whose contents are

# This is a combination of 2 commits.
# The first commit's message is:

b

# This is the 2nd commit message:

c

When you save and quit, the contents of the edited file become commit message of the new combined commit:

$ git log --pretty=oneline
18fd73d3ce748f2a58d1b566c03dd9dafe0b6b4f b and c
df239176e1a2ffac927d8b496ea00d5488481db5 a
Greg Bacon