{"thread":{"id":"17531","subject":"git rebase -i onto HEAD~n","startedAt":"2009-02-03T15:17:17Z","lastAt":"2009-02-03T17:55:08Z","messageCount":6,"participants":["Bisani, Alok","Björn Steinbrink","Sitaram Chamarty"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"102972","messageId":"C5E2CAEE4A87D24DAB5334F62A72D1F43ADC9D@ELON17P32001A.csfb.cs-group.com","threadId":"17531","inReplyTo":null,"subject":"git rebase -i onto HEAD~n","fromName":"Bisani, Alok","fromEmail":"alok.bisani@credit-suisse.com","sentAt":null,"receivedAt":"2009-02-03T15:17:17Z","isPatch":false,"sender":{"key":"alok.bisani@credit-suisse.com","avatar":null},"body":"Hi,\n\nIs it possible to use git rebase -i for the following use case, in a\nlocal branch?\n\n$ git reset --soft HEAD~3\n$ # magically squash HEAD~2 & HEAD, ignoring HEAD~1 (which should be\ndiscarded)\n$ git commit -m \"new commit replacing current HEAD~2 HEAD, without the\ncommit HEAD~1 (to be discarded)\"\n\nI get the error below.\n\n    grep: /home/user/project/.git/rebase-merge/done: No such file or\ndirectory\n    Cannot 'squash' without a previous commit\n\nOr could you please suggest another command which is meant to this.\n\nI must mention, that HEAD~3, in my case is the first commit, but I don't\nthink that makes any difference.\n\n$ git --version\ngit version 1.6.0\n\nBest regards,\nAlok\n\n==============================================================================\nPlease access the attached hyperlink for an important electronic communications disclaimer: \n\nhttp://www.credit-suisse.com/legal/en/disclaimer_email_ib.html\n==============================================================================\n"},{"id":"102975","messageId":"20090203154457.GA6859@atjola.homenet","threadId":"17531","inReplyTo":"C5E2CAEE4A87D24DAB5334F62A72D1F43ADC9D@ELON17P32001A.csfb.cs-group.com","subject":"Re: git rebase -i onto HEAD~n","fromName":"Björn Steinbrink","fromEmail":"b.steinbrink@gmx.de","sentAt":"2009-02-03T15:44:57Z","receivedAt":"2009-02-03T15:44:57Z","isPatch":false,"sender":{"key":"b.steinbrink@gmx.de","avatar":"https://avatars.githubusercontent.com/u/230962?v=4"},"body":"On 2009.02.03 15:32:35 -0000, Bisani, Alok wrote:\n> Hi,\n> \n> Is it possible to use git rebase -i for the following use case, in a\n> local branch?\n> \n> $ git reset --soft HEAD~3\n> $ # magically squash HEAD~2 & HEAD, ignoring HEAD~1 (which should be\n> discarded)\n> $ git commit -m \"new commit replacing current HEAD~2 HEAD, without the\n> commit HEAD~1 (to be discarded)\"\n> \n> I get the error below.\n> \n>     grep: /home/user/project/.git/rebase-merge/done: No such file or\n> directory\n>     Cannot 'squash' without a previous commit\n\nIt would be helpful if you told us what command you used, and what you\nchanged in the editor.\n\nThis should do:\ngit rebase -i HEAD~3\n\nAnd in the editor:\npick HEAD~2\nsquash HEAD\n\nBjörn\n"},{"id":"102980","messageId":"C5E2CAEE4A87D24DAB5334F62A72D1F43ADCA0@ELON17P32001A.csfb.cs-group.com","threadId":"17531","inReplyTo":"20090203154457.GA6859@atjola.homenet","subject":"RE: git rebase -i onto HEAD~n","fromName":"Bisani, Alok","fromEmail":"alok.bisani@credit-suisse.com","sentAt":null,"receivedAt":"2009-02-03T16:15:39Z","isPatch":false,"sender":{"key":"alok.bisani@credit-suisse.com","avatar":null},"body":">On 2009.02.03 15:32:35 -0000, Bisani, Alok wrote:\n>> Hi,\n>> \n>> Is it possible to use git rebase -i for the following use case, in a \n>> local branch?\n>> \n>> $ git reset --soft HEAD~3\n>> $ # magically squash HEAD~2 & HEAD, ignoring HEAD~1 (which should be\n>> discarded)\n>> $ git commit -m \"new commit replacing current HEAD~2 HEAD, without the \n>> commit HEAD~1 (to be discarded)\"\n>> \n>> I get the error below.\n>> \n>>     grep: /home/user/project/.git/rebase-merge/done: No such file or \n>> directory\n>>     Cannot 'squash' without a previous commit\n>\n>It would be helpful if you told us what command you used, and what you changed in the editor.\n>\n>This should do:\n>git rebase -i HEAD~3\n>\n>And in the editor:\n>pick HEAD~2\n>squash HEAD\n\nSure. Here is the sequence of commands.\n\n    mkdir gittest; cd gittest/\n    git init\n    echo \"one\" > one.txt; git add one.txt; git commit -m \"one\"\n    echo \"two\" > two.txt; git add two.txt; git commit -m \"two\"\n    echo \"bad\" > discard.txt; git add discard.txt; git commit -m \"discard\"\n    echo \"three\" > three.txt; git add three.txt; git commit -m \"three\"\n    git rebase -i HEAD~3\n\n    # Leave editor for ~/gittest/.git/rebase-merge/git-rebase-todo with\n    squash 8df4c33 two\n    # deleted line with discard\n    squash 91f8267 three\n\n    # And get this error\n    grep: /home/user/gittest/.git/rebase-merge/done: No such file or directory\n    Cannot 'squash' without a previous commit\n\nI guess the error could be introduced after commit -m \"two\" is first squashed, leaving commit -m \"three\" parentless, in the (no branch) branch?\n\nBest regards,\nAlok\n\n==============================================================================\nPlease access the attached hyperlink for an important electronic communications disclaimer: \n\nhttp://www.credit-suisse.com/legal/en/disclaimer_email_ib.html\n==============================================================================\n"},{"id":"102990","messageId":"20090203170457.GB6859@atjola.homenet","threadId":"17531","inReplyTo":"C5E2CAEE4A87D24DAB5334F62A72D1F43ADCA0@ELON17P32001A.csfb.cs-group.com","subject":"Re: git rebase -i onto HEAD~n","fromName":"Björn Steinbrink","fromEmail":"b.steinbrink@gmx.de","sentAt":"2009-02-03T17:04:57Z","receivedAt":"2009-02-03T17:04:57Z","isPatch":false,"sender":{"key":"b.steinbrink@gmx.de","avatar":"https://avatars.githubusercontent.com/u/230962?v=4"},"body":"On 2009.02.03 16:22:22 -0000, Bisani, Alok wrote:\n> >And in the editor:\n> >pick HEAD~2\n> >squash HEAD\n> \n>     # Leave editor for ~/gittest/.git/rebase-merge/git-rebase-todo with\n>     squash 8df4c33 two\n>     # deleted line with discard\n>     squash 91f8267 three\n\nNotice the difference? You're trying to squash 8df4cee into nothing. And\n_if_ that would work, it would still squash 8df4c33 into the previous\ncommit, which is not what you wanted anyway.\n\nBjörn\n"},{"id":"102993","messageId":"slrngogv3e.nak.sitaramc@sitaramc.homelinux.net","threadId":"17531","inReplyTo":"C5E2CAEE4A87D24DAB5334F62A72D1F43ADCA0@ELON17P32001A.csfb.cs-group.com","subject":"Re: git rebase -i onto HEAD~n","fromName":"Sitaram Chamarty","fromEmail":"sitaramc@gmail.com","sentAt":"2009-02-03T17:18:39Z","receivedAt":"2009-02-03T17:18:39Z","isPatch":false,"sender":{"key":"sitaramc@gmail.com","avatar":"https://avatars.githubusercontent.com/u/43316?v=4"},"body":"On 2009-02-03, Bisani, Alok <alok.bisani@credit-suisse.com> wrote:\n>     # Leave editor for ~/gittest/.git/rebase-merge/git-rebase-todo with\n>     squash 8df4c33 two\n>     # deleted line with discard\n>     squash 91f8267 three\n>\n>     # And get this error\n>     grep: /home/user/gittest/.git/rebase-merge/done: No such file or directory\n>     Cannot 'squash' without a previous commit\n\nQuoting from \"git help rebase\"'s interactive mode section:\n\n    If you want to fold two or more commits into one,\n    replace the command \"pick\" with \"squash\" for the second\n    and subsequent commit.\n\nKeep the first one as \"pick\", don't make both of them\nsquash.\n\n-- \nSitaram\n\nWe've long needed a filesystem named after a vegetable --\nAndrew Morton\n"},{"id":"103004","messageId":"C5E2CAEE4A87D24DAB5334F62A72D1F43ADCA2@ELON17P32001A.csfb.cs-group.com","threadId":"17531","inReplyTo":"20090203170457.GB6859@atjola.homenet","subject":"RE: git rebase -i onto HEAD~n","fromName":"Bisani, Alok","fromEmail":"alok.bisani@credit-suisse.com","sentAt":null,"receivedAt":"2009-02-03T17:55:08Z","isPatch":false,"sender":{"key":"alok.bisani@credit-suisse.com","avatar":null},"body":">On 2009.02.03 16:22:22 -0000, Bisani, Alok wrote:\n>> >And in the editor:\n>> >pick HEAD~2\n>> >squash HEAD\n>> \n>>     # Leave editor for ~/gittest/.git/rebase-merge/git-rebase-todo with\n>>     squash 8df4c33 two\n>>     # deleted line with discard\n>>     squash 91f8267 three\n>\n>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.\n\nYes, 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.'\n\nHowever, 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.\n\nIs there a way to have git rebase --amend the --onto commit?\n\nBest regards,\nAlok\n\n==============================================================================\nPlease access the attached hyperlink for an important electronic communications disclaimer: \n\nhttp://www.credit-suisse.com/legal/en/disclaimer_email_ib.html\n==============================================================================\n"}]}