{"thread":{"id":"25721","subject":"Newbie: Restore messed up code from local or remote repository","startedAt":"2010-11-12T08:22:43Z","lastAt":"2010-11-12T16:57:09Z","messageCount":6,"participants":["gzoller","Ramkumar Ramachandra","Jan Hudec","Santi Béjar","Matthieu Moy"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"155767","messageId":"1289550163511-5731540.post@n2.nabble.com","threadId":"25721","inReplyTo":null,"subject":"Newbie: Restore messed up code from local or remote repository","fromName":"gzoller","fromEmail":"gzoller@hotmail.com","sentAt":"2010-11-12T08:22:43Z","receivedAt":"2010-11-12T08:22:43Z","isPatch":false,"sender":{"key":"gzoller@hotmail.com","avatar":null},"body":"\nHello -- Extreme Git Newbie\n\nI have a project that is checked into a local git repository as well as\npushed to a remote repository.\n\nThrough misadventure I've managed to screw up my working code and want to\nrestore what I had from my last commit on either the local or remote\nrepositories.\n\nSo I blew away my messed up working files and tried:\n\ngit checkout\ngit pull -f /path/to/remote/repos\ngit fetch -f /path/to/remote/repos\n\nNone of the above did the trick.  The two remote commands reported that\neverything was Already up-to-date! (even though I'd deleted a lot of local\nworking files)\n\nWhat am I missing?  How can I restore my previous state from last commit?\n\nThanks!\nGreg\n-- \nView this message in context: http://git.661346.n2.nabble.com/Newbie-Restore-messed-up-code-from-local-or-remote-repository-tp5731540p5731540.html\nSent from the git mailing list archive at Nabble.com.\n"},{"id":"155770","messageId":"20101112103836.GB20053@kytes","threadId":"25721","inReplyTo":"1289550163511-5731540.post@n2.nabble.com","subject":"Re: Newbie: Restore messed up code from local or remote repository","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2010-11-12T10:38:39Z","receivedAt":"2010-11-12T10:38:39Z","isPatch":false,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi Greg,\n\ngzoller writes:\n> git checkout\n> git pull -f /path/to/remote/repos\n> git fetch -f /path/to/remote/repos\n> \n> None of the above did the trick.  The two remote commands reported that\n> everything was Already up-to-date! (even though I'd deleted a lot of local\n> working files)\n\nYes, there's really nothing to download. Everything that needs to be\nfetched has already been fetched :)\n\n> What am I missing?  How can I restore my previous state from last commit?\n\nSee `--hard` switch of `git reset`. Use with extreme caution.\n\nTo throw *everything* all your local work away and go back to the\nstate of the remote repository, switch to `master` branch and do `git\nreset --hard origin/master` where `origin` is the name of your remote\nand `master` is the name of your remote branch.\n\nTo reset to the last commit without looking at the remote, run `git\nreset --hard`.\n\nNote: Again, please understand what it's doing first; don't run it\nblindly.\n\n-- Ram\n"},{"id":"155777","messageId":"20101112124621.GF30870@efreet.light.src","threadId":"25721","inReplyTo":"1289550163511-5731540.post@n2.nabble.com","subject":"Re: Newbie: Restore messed up code from local or remote repository","fromName":"Jan Hudec","fromEmail":"bulb@ucw.cz","sentAt":"2010-11-12T12:46:21Z","receivedAt":"2010-11-12T12:46:21Z","isPatch":false,"sender":{"key":"bulb@ucw.cz","avatar":null},"body":"On Fri, Nov 12, 2010 at 00:22:43 -0800, gzoller wrote:\n> \n> Hello -- Extreme Git Newbie\n> \n> I have a project that is checked into a local git repository as well as\n> pushed to a remote repository.\n> \n> Through misadventure I've managed to screw up my working code and want to\n> restore what I had from my last commit on either the local or remote\n> repositories.\n\nIf you screwed up content of the index, you will need the 'reset' command.\n\n> So I blew away my messed up working files and tried:\n> \n> git checkout\n\nI don't think it does anything without argument. With argument '.' this\nrestores working tree to the state in index (stage). So if you have that\nscrewed up too, it won't be enough.\n\n> git pull -f /path/to/remote/repos\n\nThis is just\n    git fetch -f /path/to/remote/repos\nfollowed by\n    git merge FETCH_HEAD\n(or appropriate tracking branch if you have the remote and tracking branch\nset up)\n\nThe former ensured the latest revision of remote repo is available. It will\nnot itself\n\n> git fetch -f /path/to/remote/repos\n\nSee above.\n\n> None of the above did the trick.  The two remote commands reported that\n> everything was Already up-to-date! (even though I'd deleted a lot of local\n> working files)\n> \n> What am I missing?  How can I restore my previous state from last commit?\n\nYes, using combination of reset and checkout. First make sure the branch you\nwant to use is checked out (git status will tell you if you don't have the\ngit aware shell prompt installed).\n\nThan run\n\n   git reset --hard <the-commit-you-want-to-be-at>\n\nThat will unconditionally make the current branch point to the specified\ncommit and make both the index and the working tree match the content of the\ncommit.\n\nIf you don't want it to touch the working tree (so you can compare what you\nhad in the working tree with that commit), you'd use --mixed instead of\n--hard. You can than use checkout to revert those changes -- see above.\n\n-- \n\t\t\t\t\t\t Jan 'Bulb' Hudec <bulb@ucw.cz>\n"},{"id":"155780","messageId":"AANLkTinyhGKbLDJSsu19+capPUgCx0m_5feaOoSuXCm8@mail.gmail.com","threadId":"25721","inReplyTo":"20101112124621.GF30870@efreet.light.src","subject":"Re: Newbie: Restore messed up code from local or remote repository","fromName":"Santi Béjar","fromEmail":"santi@agolina.net","sentAt":"2010-11-12T14:02:45Z","receivedAt":"2010-11-12T14:02:45Z","isPatch":false,"sender":{"key":"santi@agolina.net","avatar":null},"body":"On Fri, Nov 12, 2010 at 1:46 PM, Jan Hudec <bulb@ucw.cz> wrote:\n> On Fri, Nov 12, 2010 at 00:22:43 -0800, gzoller wrote:\n>>\n>> Hello -- Extreme Git Newbie\n>>\n>> I have a project that is checked into a local git repository as well as\n>> pushed to a remote repository.\n>>\n>> Through misadventure I've managed to screw up my working code and want to\n>> restore what I had from my last commit on either the local or remote\n>> repositories.\n>\n> If you screwed up content of the index, you will need the 'reset' command.\n>\n\nIf the problem is that you messed with the index (stage) or the\nworking directory and you want to discard local changes to them, you\ncould also execute \"git status\" and follow the instruccions there. If\nthat is not enough, report it here.\n\nHTH,\nSanti\n"},{"id":"155788","messageId":"1289580622725-5733041.post@n2.nabble.com","threadId":"25721","inReplyTo":"AANLkTinyhGKbLDJSsu19+capPUgCx0m_5feaOoSuXCm8@mail.gmail.com","subject":"Re: Newbie: Restore messed up code from local or remote repository","fromName":"gzoller","fromEmail":"gzoller@hotmail.com","sentAt":"2010-11-12T16:50:22Z","receivedAt":"2010-11-12T16:50:22Z","isPatch":false,"sender":{"key":"gzoller@hotmail.com","avatar":null},"body":"\nThat's cool!  Did the trick, thanks!\n\nWhile I may get into the fancy stuff of branching (need to read a book on\ngit) usually I use it to protect myself from self-inflicted harm, and want\nto go back to a happy place in such cases.\n-- \nView this message in context: http://git.661346.n2.nabble.com/Newbie-Restore-messed-up-code-from-local-or-remote-repository-tp5731540p5733041.html\nSent from the git mailing list archive at Nabble.com.\n"},{"id":"155789","messageId":"vpqzkte1nve.fsf@bauges.imag.fr","threadId":"25721","inReplyTo":"20101112124621.GF30870@efreet.light.src","subject":"Re: Newbie: Restore messed up code from local or remote repository","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2010-11-12T16:57:09Z","receivedAt":"2010-11-12T16:57:09Z","isPatch":false,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Jan Hudec <bulb@ucw.cz> writes:\n\n>> git checkout\n>\n> I don't think it does anything without argument. With argument '.' this\n> restores working tree to the state in index (stage). So if you have that\n> screwed up too, it won't be enough.\n\nActually, the output of \"git status\" will give you the right command\nhere.\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"}]}