{"thread":{"id":"23678","subject":"how to squash a few commits in the past","startedAt":"2010-05-03T09:33:56Z","lastAt":"2010-05-06T06:45:49Z","messageCount":8,"participants":["Gelonida","Michael J Gruber","Ramkumar Ramachandra","Johannes Sixt"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"140818","messageId":"loom.20100503T112508-677@post.gmane.org","threadId":"23678","inReplyTo":null,"subject":"how to squash a few commits in the past","fromName":"Gelonida","fromEmail":"gelonida@gmail.com","sentAt":"2010-05-03T09:33:56Z","receivedAt":"2010-05-03T09:33:56Z","isPatch":false,"sender":{"key":"gelonida@gmail.com","avatar":null},"body":"Hi,\n\n\n\nI posted already a similiar question about how to squash the all the commit\nhostory older than a certain commit into one commit.\n\n\nThis question is slightly different.\n\n\nI'm having a git repository.\n\nSuddenly I noticed, that git pull became rather slow.\n\nThe reason:\nOne of the team members accidentally commited a very huge file together with\nsome useful sources.\na few commits later he noticed his error and removed the huge file.\n\n\n\nThe plan would be:\n- create a new git repository without the huge file\n- let everybody clone the new repository and continue working.\n\n\nI thought, that I could squash the commit adding the file, removing the file and\nthe commits in between into one commit.\n\nHow could I do this?\n\n\nThanks a lot for your help.\n"},{"id":"140820","messageId":"4BDEA0D7.9090201@drmicha.warpmail.net","threadId":"23678","inReplyTo":"loom.20100503T112508-677@post.gmane.org","subject":"Re: how to squash a few commits in the past","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2010-05-03T10:09:27Z","receivedAt":"2010-05-03T10:09:27Z","isPatch":false,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Gelonida venit, vidit, dixit 03.05.2010 11:33:\n> Hi,\n> \n> \n> \n> I posted already a similiar question about how to squash the all the commit\n> hostory older than a certain commit into one commit.\n> \n> \n> This question is slightly different.\n> \n> \n> I'm having a git repository.\n> \n> Suddenly I noticed, that git pull became rather slow.\n> \n> The reason:\n> One of the team members accidentally commited a very huge file together with\n> some useful sources.\n> a few commits later he noticed his error and removed the huge file.\n> \n> \n> \n> The plan would be:\n> - create a new git repository without the huge file\n> - let everybody clone the new repository and continue working.\n> \n> \n> I thought, that I could squash the commit adding the file, removing the file and\n> the commits in between into one commit.\n\nYou don't need to squash the commits in between. Use git rebase -i A^ if\nA is the commit introducing the large file. Then, either edit that first\ncommit (to not add the file) or reorder so that the removal commit is\nsquashed into A.\n\nIf everything looks fine people can pull and rebase. Note that in the\nsource repository, there will still be a large \"blob\" until you prune\nand repack.\n\nMichael\n"},{"id":"140847","messageId":"hrncm3$pg8$1@dough.gmane.org","threadId":"23678","inReplyTo":"4BDEA0D7.9090201@drmicha.warpmail.net","subject":"Re: how to squash a few commits in the past","fromName":"Gelonida","fromEmail":"gelonida@gmail.com","sentAt":"2010-05-03T20:45:55Z","receivedAt":"2010-05-03T20:45:55Z","isPatch":false,"sender":{"key":"gelonida@gmail.com","avatar":null},"body":"Hi Michael,\n\nMichael J Gruber wrote:\n> Gelonida venit, vidit, dixit 03.05.2010 11:33:\n>>\n>>\n>> The plan would be:\n>> - create a new git repository without the huge file\n>> - let everybody clone the new repository and continue working.\n>>\n>>\n>> I thought, that I could squash the commit adding the file, removing the file and\n>> the commits in between into one commit.\n> \n> You don't need to squash the commits in between. Use git rebase -i A^ if\n> A is the commit introducing the large file. Then, either edit that first\n> commit (to not add the file) or reorder so that the removal commit is\n> squashed into A.\n\n\nI seem to misunderstand your suggestion.\n\ngit rebase -i 740ebdf9b^\nreturns following output\n> fatal: Needed a single revision\n> Invalid base\n\n\nwhat am I missing?\n"},{"id":"140849","messageId":"hrnd84$rh0$1@dough.gmane.org","threadId":"23678","inReplyTo":"hrncm3$pg8$1@dough.gmane.org","subject":"Re: how to squash a few commits in the past","fromName":"Gelonida","fromEmail":"gelonida@gmail.com","sentAt":"2010-05-03T20:55:32Z","receivedAt":"2010-05-03T20:55:32Z","isPatch":false,"sender":{"key":"gelonida@gmail.com","avatar":null},"body":"Hi,\n\nGelonida wrote:\n> Hi Michael,\n> \n> Michael J Gruber wrote:\n>> Gelonida venit, vidit, dixit 03.05.2010 11:33:\n>>>\n>>> The plan would be:\n>>> - create a new git repository without the huge file\n>>> - let everybody clone the new repository and continue working.\n>>>\n>>>\n>>> I thought, that I could squash the commit adding the file, removing the file and\n>>> the commits in between into one commit.\n>> You don't need to squash the commits in between. Use git rebase -i A^ if\n>> A is the commit introducing the large file. Then, either edit that first\n>> commit (to not add the file) or reorder so that the removal commit is\n>> squashed into A.\n> \n> \n> I seem to misunderstand your suggestion.\n> \n> git rebase -i 740ebdf9b^\n> returns following output\n>> fatal: Needed a single revision\n>> Invalid base\n> \n> \n> what am I missing?\n\nIn case it is relevent:\n\nMy git version:\ngit version 1.6.3.3\n"},{"id":"140854","messageId":"hrnem4$1m0$1@dough.gmane.org","threadId":"23678","inReplyTo":"hrncm3$pg8$1@dough.gmane.org","subject":"Re: how to squash a few commits in the past","fromName":"Gelonida","fromEmail":"gelonida@gmail.com","sentAt":"2010-05-03T21:20:03Z","receivedAt":"2010-05-03T21:20:03Z","isPatch":false,"sender":{"key":"gelonida@gmail.com","avatar":null},"body":"Hi Michael,\n\nGelonida wrote:\n> Hi Michael,\n> \n> Michael J Gruber wrote:\n>> Gelonida venit, vidit, dixit 03.05.2010 11:33:\n>>>\n>>> The plan would be:\n>>> - create a new git repository without the huge file\n>>> - let everybody clone the new repository and continue working.\n>>>\n>>>\n>>> I thought, that I could squash the commit adding the file, removing the file and\n>>> the commits in between into one commit.\n>> You don't need to squash the commits in between. Use git rebase -i A^ if\n>> A is the commit introducing the large file. Then, either edit that first\n>> commit (to not add the file) or reorder so that the removal commit is\n>> squashed into A.\n> \n> \n> I seem to misunderstand your suggestion.\n> \n> git rebase -i 740ebdf9b^\n> returns following output\n>> fatal: Needed a single revision\n>> Invalid base\n\n\nPlease ignore me previous reply.\nIt is very embarassing, but I tried it in the wrong window and therefore\nwrong directory.\n\n\nNow I'm back to other errors.\nWhat I did was:\n\ngit rebase -i 740ebdf9^\n# as a very first test I tried to modify nothing at all.\n# So I just quit the editor window (with about 270 entries)\n# where I could choose what to pick, squash or ignore\n\n\nThe result:\nthe counter counts to about 50 of my 270 commits and then\ncommand aborts then\n\n> Automatic cherry-pick failed.  After resolving the conflicts,\n> mark the corrected paths with 'git add <paths>', and\n> run 'git rebase --continue'\n> Could not apply 67f3f6d... preparation for #241\n\nI guess, that the problem might be. that the version tree looks roughly\nlike this:\n\n# first line of tree\nA-B-C-<forksoff>-D-E-F-G-<all_joined>-H-I-J-<forks_off>--K-\n\n\n#tree continues after\n\nK-L-<all_joined>-M-N\n\n\nHowever, the commit, that I want to fix is commit I,\n\nI think git gets lost somehow between J and L\n\nIs it normal, that git gets lost wehn rebasing such a structure.\n"},{"id":"140981","messageId":"w2zf3271551005050619td67d697y97d7e9181c4496fc@mail.gmail.com","threadId":"23678","inReplyTo":"hrnem4$1m0$1@dough.gmane.org","subject":"Re: how to squash a few commits in the past","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2010-05-05T13:19:10Z","receivedAt":"2010-05-05T13:19:10Z","isPatch":false,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi,\n\nOn Mon, May 3, 2010 at 11:20 PM, Gelonida <gelonida@gmail.com> wrote:\n> Is it normal, that git gets lost wehn rebasing such a structure.\n\nWhile performing an interactive rebase, conflicts can often occur and\nthis is quite normal.\n\n>> Automatic cherry-pick failed.  After resolving the conflicts,\n>> mark the corrected paths with 'git add <paths>', and\n>> run 'git rebase --continue'\n>> Could not apply 67f3f6d... preparation for #241\n\nThe problem and solution is described in that message. Open the file,\nresolve the conflict and continue the rebase operation.\n\n-- Ram\n"},{"id":"141014","messageId":"4BE1E5F6.3040606@gmail.com","threadId":"23678","inReplyTo":"w2zf3271551005050619td67d697y97d7e9181c4496fc@mail.gmail.com","subject":"Re: how to squash a few commits in the past","fromName":"Gelonida","fromEmail":"gelonida@gmail.com","sentAt":"2010-05-05T21:41:10Z","receivedAt":"2010-05-05T21:41:10Z","isPatch":false,"sender":{"key":"gelonida@gmail.com","avatar":null},"body":"Hi Ragu,\n\nRamkumar Ramachandra wrote:\n> Hi,\n> \n> On Mon, May 3, 2010 at 11:20 PM, Gelonida <gelonida@gmail.com> wrote:\n>> Is it normal, that git gets lost wehn rebasing such a structure.\n> \n> While performing an interactive rebase, conflicts can often occur and\n> this is quite normal.\n> \n>>> Automatic cherry-pick failed.  After resolving the conflicts,\n>>> mark the corrected paths with 'git add <paths>', and\n>>> run 'git rebase --continue'\n>>> Could not apply 67f3f6d... preparation for #241\n> \n> The problem and solution is described in that message. Open the file,\n> resolve the conflict and continue the rebase operation.\n\n\n\nYes merging manually could be a theortical solution, but I really don't\nunderstand, why I should merge anything at all.\n\n\n\nThe history is purely linear at the places where I want to squash.\n\nThese two commits precede a few more consecutive commits, traverse then\na tree which forks to multiple branches, which partially cherrypick from\neach other and will then join again to a unique linear sequence.\n\nIf I have a history of several hundred commits and I am asked several\ntimes to merge, just because I want to squash two consecutve commits\nwithout any branches going out or in, then something (probably the way I\ntry to attack the problem or much less likely a mysterious git bug) is\nkind of wrong.\n\n\n\nI'm still looking for a solution, where I specify only the commits to be\nsquashed and everything else stays untouched without any further\nuserinteraction\n"},{"id":"141037","messageId":"4BE2659D.2070208@viscovery.net","threadId":"23678","inReplyTo":"loom.20100503T112508-677@post.gmane.org","subject":"Re: how to squash a few commits in the past","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2010-05-06T06:45:49Z","receivedAt":"2010-05-06T06:45:49Z","isPatch":false,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 5/3/2010 11:33, schrieb Gelonida:\n> One of the team members accidentally commited a very huge file together with\n> some useful sources.\n> a few commits later he noticed his error and removed the huge file.\n> \n> The plan would be:\n> - create a new git repository without the huge file\n> - let everybody clone the new repository and continue working.\n\nUse 'git filter-branch':\n\n  git filter-branch \\\n    --index-filter 'git rm --ignore-unmatch --cached the/huge/file' \\\n    --prune-empty \\\n    -- --all\n\nThe --prune-empty removes the commit that removed the file from the\nhistory if the removal of the/huge/file was the only thing it did.\n\nIf you have tags that must be rewritten, add \"--tag-name-filter cat\" to\nthe command before \"--\".\n\nTry this in a backup copy or clone first!\n\n-- Hannes\n"}]}