From: Jan Hudec <bulb@ucw.cz>
To: gzoller <gzoller@hotmail.com>
Cc: git@vger.kernel.org
Subject: Re: Newbie: Restore messed up code from local or remote repository
Date: Fri, 12 Nov 2010 13:46:21 +0100 [thread overview]
Message-ID: <20101112124621.GF30870@efreet.light.src> (raw)
In-Reply-To: <1289550163511-5731540.post@n2.nabble.com>
On Fri, Nov 12, 2010 at 00:22:43 -0800, gzoller wrote:
>
> Hello -- Extreme Git Newbie
>
> I have a project that is checked into a local git repository as well as
> pushed to a remote repository.
>
> Through misadventure I've managed to screw up my working code and want to
> restore what I had from my last commit on either the local or remote
> repositories.
If you screwed up content of the index, you will need the 'reset' command.
> So I blew away my messed up working files and tried:
>
> git checkout
I don't think it does anything without argument. With argument '.' this
restores working tree to the state in index (stage). So if you have that
screwed up too, it won't be enough.
> git pull -f /path/to/remote/repos
This is just
git fetch -f /path/to/remote/repos
followed by
git merge FETCH_HEAD
(or appropriate tracking branch if you have the remote and tracking branch
set up)
The former ensured the latest revision of remote repo is available. It will
not itself
> git fetch -f /path/to/remote/repos
See above.
> None of the above did the trick. The two remote commands reported that
> everything was Already up-to-date! (even though I'd deleted a lot of local
> working files)
>
> What am I missing? How can I restore my previous state from last commit?
Yes, using combination of reset and checkout. First make sure the branch you
want to use is checked out (git status will tell you if you don't have the
git aware shell prompt installed).
Than run
git reset --hard <the-commit-you-want-to-be-at>
That will unconditionally make the current branch point to the specified
commit and make both the index and the working tree match the content of the
commit.
If you don't want it to touch the working tree (so you can compare what you
had in the working tree with that commit), you'd use --mixed instead of
--hard. You can than use checkout to revert those changes -- see above.
--
Jan 'Bulb' Hudec <bulb@ucw.cz>
next prev parent reply other threads:[~2010-11-12 12:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-12 8:22 Newbie: Restore messed up code from local or remote repository gzoller
2010-11-12 10:38 ` Ramkumar Ramachandra
2010-11-12 12:46 ` Jan Hudec [this message]
2010-11-12 14:02 ` Santi Béjar
2010-11-12 16:50 ` gzoller
2010-11-12 16:57 ` Matthieu Moy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20101112124621.GF30870@efreet.light.src \
--to=bulb@ucw.cz \
--cc=git@vger.kernel.org \
--cc=gzoller@hotmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).