All of lore.kernel.org
 help / color / mirror / Atom feed
* Newbie:  Restore messed up code from local or remote repository
@ 2010-11-12  8:22 gzoller
  2010-11-12 10:38 ` Ramkumar Ramachandra
  2010-11-12 12:46 ` Jan Hudec
  0 siblings, 2 replies; 6+ messages in thread
From: gzoller @ 2010-11-12  8:22 UTC (permalink / raw)
  To: git


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.

So I blew away my messed up working files and tried:

git checkout
git pull -f /path/to/remote/repos
git fetch -f /path/to/remote/repos

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?

Thanks!
Greg
-- 
View this message in context: http://git.661346.n2.nabble.com/Newbie-Restore-messed-up-code-from-local-or-remote-repository-tp5731540p5731540.html
Sent from the git mailing list archive at Nabble.com.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Newbie:  Restore messed up code from local or remote repository
  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
  1 sibling, 0 replies; 6+ messages in thread
From: Ramkumar Ramachandra @ 2010-11-12 10:38 UTC (permalink / raw)
  To: gzoller; +Cc: git

Hi Greg,

gzoller writes:
> git checkout
> git pull -f /path/to/remote/repos
> git fetch -f /path/to/remote/repos
> 
> 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)

Yes, there's really nothing to download. Everything that needs to be
fetched has already been fetched :)

> What am I missing?  How can I restore my previous state from last commit?

See `--hard` switch of `git reset`. Use with extreme caution.

To throw *everything* all your local work away and go back to the
state of the remote repository, switch to `master` branch and do `git
reset --hard origin/master` where `origin` is the name of your remote
and `master` is the name of your remote branch.

To reset to the last commit without looking at the remote, run `git
reset --hard`.

Note: Again, please understand what it's doing first; don't run it
blindly.

-- Ram

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Newbie:  Restore messed up code from local or remote repository
  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
  2010-11-12 14:02   ` Santi Béjar
  2010-11-12 16:57   ` Matthieu Moy
  1 sibling, 2 replies; 6+ messages in thread
From: Jan Hudec @ 2010-11-12 12:46 UTC (permalink / raw)
  To: gzoller; +Cc: git

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>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Newbie: Restore messed up code from local or remote repository
  2010-11-12 12:46 ` Jan Hudec
@ 2010-11-12 14:02   ` Santi Béjar
  2010-11-12 16:50     ` gzoller
  2010-11-12 16:57   ` Matthieu Moy
  1 sibling, 1 reply; 6+ messages in thread
From: Santi Béjar @ 2010-11-12 14:02 UTC (permalink / raw)
  To: Jan Hudec; +Cc: gzoller, git

On Fri, Nov 12, 2010 at 1:46 PM, Jan Hudec <bulb@ucw.cz> wrote:
> 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.
>

If the problem is that you messed with the index (stage) or the
working directory and you want to discard local changes to them, you
could also execute "git status" and follow the instruccions there. If
that is not enough, report it here.

HTH,
Santi

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Newbie: Restore messed up code from local or remote repository
  2010-11-12 14:02   ` Santi Béjar
@ 2010-11-12 16:50     ` gzoller
  0 siblings, 0 replies; 6+ messages in thread
From: gzoller @ 2010-11-12 16:50 UTC (permalink / raw)
  To: git


That's cool!  Did the trick, thanks!

While I may get into the fancy stuff of branching (need to read a book on
git) usually I use it to protect myself from self-inflicted harm, and want
to go back to a happy place in such cases.
-- 
View this message in context: http://git.661346.n2.nabble.com/Newbie-Restore-messed-up-code-from-local-or-remote-repository-tp5731540p5733041.html
Sent from the git mailing list archive at Nabble.com.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Newbie:  Restore messed up code from local or remote repository
  2010-11-12 12:46 ` Jan Hudec
  2010-11-12 14:02   ` Santi Béjar
@ 2010-11-12 16:57   ` Matthieu Moy
  1 sibling, 0 replies; 6+ messages in thread
From: Matthieu Moy @ 2010-11-12 16:57 UTC (permalink / raw)
  To: Jan Hudec; +Cc: gzoller, git

Jan Hudec <bulb@ucw.cz> writes:

>> 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.

Actually, the output of "git status" will give you the right command
here.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-11-12 16:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2010-11-12 14:02   ` Santi Béjar
2010-11-12 16:50     ` gzoller
2010-11-12 16:57   ` Matthieu Moy

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.