Git development
 help / color / mirror / Atom feed
* git rebase -i onto HEAD~n
@ 2009-02-03 15:32 Bisani, Alok
  2009-02-03 15:44 ` Björn Steinbrink
  0 siblings, 1 reply; 6+ messages in thread
From: Bisani, Alok @ 2009-02-03 15:32 UTC (permalink / raw)
  To: git

Hi,

Is it possible to use git rebase -i for the following use case, in a
local branch?

$ git reset --soft HEAD~3
$ # magically squash HEAD~2 & HEAD, ignoring HEAD~1 (which should be
discarded)
$ git commit -m "new commit replacing current HEAD~2 HEAD, without the
commit HEAD~1 (to be discarded)"

I get the error below.

    grep: /home/user/project/.git/rebase-merge/done: No such file or
directory
    Cannot 'squash' without a previous commit

Or could you please suggest another command which is meant to this.

I must mention, that HEAD~3, in my case is the first commit, but I don't
think that makes any difference.

$ git --version
git version 1.6.0

Best regards,
Alok

==============================================================================
Please access the attached hyperlink for an important electronic communications disclaimer: 

http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html
==============================================================================

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: git rebase -i onto HEAD~n
  2009-02-03 15:32 git rebase -i onto HEAD~n Bisani, Alok
@ 2009-02-03 15:44 ` Björn Steinbrink
  2009-02-03 16:22   ` Bisani, Alok
  0 siblings, 1 reply; 6+ messages in thread
From: Björn Steinbrink @ 2009-02-03 15:44 UTC (permalink / raw)
  To: Bisani, Alok; +Cc: git

On 2009.02.03 15:32:35 -0000, Bisani, Alok wrote:
> Hi,
> 
> Is it possible to use git rebase -i for the following use case, in a
> local branch?
> 
> $ git reset --soft HEAD~3
> $ # magically squash HEAD~2 & HEAD, ignoring HEAD~1 (which should be
> discarded)
> $ git commit -m "new commit replacing current HEAD~2 HEAD, without the
> commit HEAD~1 (to be discarded)"
> 
> I get the error below.
> 
>     grep: /home/user/project/.git/rebase-merge/done: No such file or
> directory
>     Cannot 'squash' without a previous commit

It would be helpful if you told us what command you used, and what you
changed in the editor.

This should do:
git rebase -i HEAD~3

And in the editor:
pick HEAD~2
squash HEAD

Björn

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: git rebase -i onto HEAD~n
  2009-02-03 15:44 ` Björn Steinbrink
@ 2009-02-03 16:22   ` Bisani, Alok
  2009-02-03 17:04     ` Björn Steinbrink
  2009-02-03 17:18     ` Sitaram Chamarty
  0 siblings, 2 replies; 6+ messages in thread
From: Bisani, Alok @ 2009-02-03 16:22 UTC (permalink / raw)
  To: Björn Steinbrink; +Cc: git

>On 2009.02.03 15:32:35 -0000, Bisani, Alok wrote:
>> Hi,
>> 
>> Is it possible to use git rebase -i for the following use case, in a 
>> local branch?
>> 
>> $ git reset --soft HEAD~3
>> $ # magically squash HEAD~2 & HEAD, ignoring HEAD~1 (which should be
>> discarded)
>> $ git commit -m "new commit replacing current HEAD~2 HEAD, without the 
>> commit HEAD~1 (to be discarded)"
>> 
>> I get the error below.
>> 
>>     grep: /home/user/project/.git/rebase-merge/done: No such file or 
>> directory
>>     Cannot 'squash' without a previous commit
>
>It would be helpful if you told us what command you used, and what you changed in the editor.
>
>This should do:
>git rebase -i HEAD~3
>
>And in the editor:
>pick HEAD~2
>squash HEAD

Sure. Here is the sequence of commands.

    mkdir gittest; cd gittest/
    git init
    echo "one" > one.txt; git add one.txt; git commit -m "one"
    echo "two" > two.txt; git add two.txt; git commit -m "two"
    echo "bad" > discard.txt; git add discard.txt; git commit -m "discard"
    echo "three" > three.txt; git add three.txt; git commit -m "three"
    git rebase -i HEAD~3

    # Leave editor for ~/gittest/.git/rebase-merge/git-rebase-todo with
    squash 8df4c33 two
    # deleted line with discard
    squash 91f8267 three

    # And get this error
    grep: /home/user/gittest/.git/rebase-merge/done: No such file or directory
    Cannot 'squash' without a previous commit

I guess the error could be introduced after commit -m "two" is first squashed, leaving commit -m "three" parentless, in the (no branch) branch?

Best regards,
Alok

==============================================================================
Please access the attached hyperlink for an important electronic communications disclaimer: 

http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html
==============================================================================

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: git rebase -i onto HEAD~n
  2009-02-03 16:22   ` Bisani, Alok
@ 2009-02-03 17:04     ` Björn Steinbrink
  2009-02-03 18:00       ` Bisani, Alok
  2009-02-03 17:18     ` Sitaram Chamarty
  1 sibling, 1 reply; 6+ messages in thread
From: Björn Steinbrink @ 2009-02-03 17:04 UTC (permalink / raw)
  To: Bisani, Alok; +Cc: git

On 2009.02.03 16:22:22 -0000, Bisani, Alok wrote:
> >And in the editor:
> >pick HEAD~2
> >squash HEAD
> 
>     # Leave editor for ~/gittest/.git/rebase-merge/git-rebase-todo with
>     squash 8df4c33 two
>     # deleted line with discard
>     squash 91f8267 three

Notice the difference? You're trying to squash 8df4cee into nothing. And
_if_ that would work, it would still squash 8df4c33 into the previous
commit, which is not what you wanted anyway.

Björn

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: git rebase -i onto HEAD~n
  2009-02-03 16:22   ` Bisani, Alok
  2009-02-03 17:04     ` Björn Steinbrink
@ 2009-02-03 17:18     ` Sitaram Chamarty
  1 sibling, 0 replies; 6+ messages in thread
From: Sitaram Chamarty @ 2009-02-03 17:18 UTC (permalink / raw)
  To: git

On 2009-02-03, Bisani, Alok <alok.bisani@credit-suisse.com> wrote:
>     # Leave editor for ~/gittest/.git/rebase-merge/git-rebase-todo with
>     squash 8df4c33 two
>     # deleted line with discard
>     squash 91f8267 three
>
>     # And get this error
>     grep: /home/user/gittest/.git/rebase-merge/done: No such file or directory
>     Cannot 'squash' without a previous commit

Quoting from "git help rebase"'s interactive mode section:

    If you want to fold two or more commits into one,
    replace the command "pick" with "squash" for the second
    and subsequent commit.

Keep the first one as "pick", don't make both of them
squash.

-- 
Sitaram

We've long needed a filesystem named after a vegetable --
Andrew Morton

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: git rebase -i onto HEAD~n
  2009-02-03 17:04     ` Björn Steinbrink
@ 2009-02-03 18:00       ` Bisani, Alok
  0 siblings, 0 replies; 6+ messages in thread
From: Bisani, Alok @ 2009-02-03 18:00 UTC (permalink / raw)
  To: Björn Steinbrink; +Cc: git

>On 2009.02.03 16:22:22 -0000, Bisani, Alok wrote:
>> >And in the editor:
>> >pick HEAD~2
>> >squash HEAD
>> 
>>     # Leave editor for ~/gittest/.git/rebase-merge/git-rebase-todo with
>>     squash 8df4c33 two
>>     # deleted line with discard
>>     squash 91f8267 three
>
>Notice the difference? You're trying to squash 8df4cee into nothing. And _if_ that would work, it would still squash 8df4c33 into the previous commit, which is not what you wanted anyway.

Yes, it is clear now. Thank you. And actually, the help page http://www.kernel.org/pub/software/scm/git/docs/git-rebase.html states this clearly as well: 'If you want to fold two or more commits into one, replace the command "pick" with "squash" for the *second_and_subsequent* commit.'

However, I _did_ want to squash 8df4c33 (HEAD~2) etc, into HEAD~3 (the first commit). But unfortunately I cannot do $ git rebase -i  HEAD~4, as HEAD~3 is the first commit. Although, I understand that it will hardly be ever used in practise.

Is there a way to have git rebase --amend the --onto commit?

Best regards,
Alok

==============================================================================
Please access the attached hyperlink for an important electronic communications disclaimer: 

http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html
==============================================================================

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2009-02-03 18:02 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-03 15:32 git rebase -i onto HEAD~n Bisani, Alok
2009-02-03 15:44 ` Björn Steinbrink
2009-02-03 16:22   ` Bisani, Alok
2009-02-03 17:04     ` Björn Steinbrink
2009-02-03 18:00       ` Bisani, Alok
2009-02-03 17:18     ` Sitaram Chamarty

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox