{"thread":{"id":"6320","subject":"Recovering from an aborted git-rebase?","startedAt":"2007-01-09T23:20:33Z","lastAt":"2007-01-10T18:53:31Z","messageCount":4,"participants":["Steven Grimm","Shawn O. Pearce","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"31302","messageId":"45A42341.8040304@midwinter.com","threadId":"6320","inReplyTo":null,"subject":"Recovering from an aborted git-rebase?","fromName":"Steven Grimm","fromEmail":"koreth@midwinter.com","sentAt":"2007-01-09T23:20:33Z","receivedAt":"2007-01-09T23:20:33Z","isPatch":false,"sender":{"key":"koreth@midwinter.com","avatar":"https://gravatar.com/avatar/71b4d2e8b62f168bdc9e9205341159e3567003b4f9e2127c617c5fa0a1f5bad2?d=mp&s=160"},"body":"Got this from one of the other people here who's using git. Luckily he \nwas able to restore his repo from a filesystem snapshot, so no permanent \nharm done, but what's the pure-git way to recover from this? Are the \nrevisions in question really gone?\n\n---\nI have 3 branches:\nmaster\nfql\nfql-new\nmaster is basically just the same as remotes/git-svn, fql is a bunch of\nchanges on top of that, and then fql-new is a new version of FQL so it makes\nchanges on top of the changes in fql (with the intention being to make it\neasy to jump back if I didn't wind up liking the new version).\nunfortunately perhaps I made it too easy, as now fql and fql-new are\nidentical and I can't get the additional set of changes back for fql-new.\n\nGenerally when I want to sync up to SVN I just fetch it in master and then\nrebase everything to its parent branch - basically my goal being to get git\nshow-branch to look the same as it did before the fetch.  This time I did\nthe fetch command in fql-new instead of master, which I'm pretty sure I've\ndone before with no real harm done.  Anyway, here's what I did:\n(in fql-new branch)\ndev005:~/www-git$ git svn fetch\n<pulls in the usual updates>\ndev005:~/www-git$ git rebase fql\nCurrent branch fql-new is up to date.\ndev005:~/www-git$ git checkout master\ndev005:~/www-git$ git rebase remotes/git-svn\nFirst, rewinding head to replay your work on top of it...\nHEAD is now at a5074e5... Fix IE6 display bug on photo_comments\nFast-forwarded master to remotes/git-svn.\ndev005:~/www-git$ git checkout fql\ndev005:~/www-git$ git rebase master\n<works normally, lots of output spew>\ndev005:~/www-git$ git checkout fql-new\ndev005:~/www-git$ git rebase master\nFirst, rewinding head to replay your work on top of it...\nHEAD is now at a5074e5... Fix IE6 display bug on photo_comments\n*********\nat this point I think to myself \"oops, I meant to rebase to fql, not to\nmaster\" and press ctrl+c\n*********\ndev005:~/www-git$ git rebase fql\nFirst, rewinding head to replay your work on top of it...\nHEAD is now at 7b49c62... split up some fql/fields/ files to more closely\nmatch the actual tables we have\nFast-forwarded fql-new to fql.\n******\nnotice that it doesn't apply any changes on top of fql and doesn't output\nany spew here\n*******\ndev005:~/www-git$\n\nand just like that, now all those changes from fql to fql-new are totally\nlost.  git log and git show-branch show no trace of them.\n"},{"id":"31304","messageId":"20070109232949.GB30023@spearce.org","threadId":"6320","inReplyTo":"45A42341.8040304@midwinter.com","subject":"Re: Recovering from an aborted git-rebase?","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-01-09T23:29:49Z","receivedAt":"2007-01-09T23:29:49Z","isPatch":false,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Steven Grimm <koreth@midwinter.com> wrote:\n> Got this from one of the other people here who's using git. Luckily he \n> was able to restore his repo from a filesystem snapshot, so no permanent \n> harm done, but what's the pure-git way to recover from this? Are the \n> revisions in question really gone?\n\nTry `git lost-found` before you use `git prune` (or also now `git gc`).\n\nAlso, if you have relogs enabled on your work branches (and I hope\nyou do, as its now the default) you can look at the branch from\nearlier, e.g.:\n\n\tgit log HEAD@{5.minutes.ago}\nor\n\tgit log HEAD@{1}\n\nto look at HEAD was just before `git rebase` did the reset.  Which\nwould be the commit you lost, but want back.\n\n\nUnfortunately we don't really have a reflog viewing utility yet so\nyou just have to sort of guess around with the @{...} syntax to find\nwhat you are looking for.  But if you can locate the correct SHA1\nfor the last commit you want back you can do a `git reset --hard $sha1`\nto restore your working branch, then do the rebase the way you meant to.\n \n-- \nShawn.\n"},{"id":"31322","messageId":"7v3b6jiv82.fsf@assigned-by-dhcp.cox.net","threadId":"6320","inReplyTo":"45A42341.8040304@midwinter.com","subject":"Re: Recovering from an aborted git-rebase?","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-01-10T00:25:17Z","receivedAt":"2007-01-10T00:25:17Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Steven Grimm <koreth@midwinter.com> writes:\n\n> dev005:~/www-git$ git rebase master\n> First, rewinding head to replay your work on top of it...\n> HEAD is now at a5074e5... Fix IE6 display bug on photo_comments\n> *********\n> at this point I think to myself \"oops, I meant to rebase to fql, not to\n> master\" and press ctrl+c\n> *********\n\nDoesn't \"git rebase --abort\" work for you at this point?\n"},{"id":"31406","messageId":"45A5362B.3030204@midwinter.com","threadId":"6320","inReplyTo":"7v3b6jiv82.fsf@assigned-by-dhcp.cox.net","subject":"Re: Recovering from an aborted git-rebase?","fromName":"Steven Grimm","fromEmail":"koreth@midwinter.com","sentAt":"2007-01-10T18:53:31Z","receivedAt":"2007-01-10T18:53:31Z","isPatch":false,"sender":{"key":"koreth@midwinter.com","avatar":"https://gravatar.com/avatar/71b4d2e8b62f168bdc9e9205341159e3567003b4f9e2127c617c5fa0a1f5bad2?d=mp&s=160"},"body":"Junio C Hamano wrote:\n > Doesn't \"git rebase --abort\" work for you at this point?\n\nIt probably would have, but he ran another \"git rebase\" immediately \nafter hitting ctrl-C, not realizing that the interrupted one had left \nthings in an odd state. I tried --abort after the fact and it said there \nwas no rebase in progress; I assume the second rebase wiped out the \ntemporary state from the first one.\n\nHowever, all's well; Shawn's suggestion of using the reflog worked fine. \nWe were able to reset back to HEAD@{3 hours ago} then do the rebase \nagain, and it did the right thing. Even though we had a filesystem \nsnapshot to fall back on, needless to say we were very happy to see \nthere was a way to recover using nothing but git commands.\n\nHooray for the reflog being turned on by default!\n\n-Steve\n"}]}