git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* can git reset or checkout be reverted?
@ 2009-02-06 14:19 bill lam
  2009-02-06 14:43 ` Matthieu Moy
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: bill lam @ 2009-02-06 14:19 UTC (permalink / raw)
  To: git

If I want to recall a old version of testing by

git reset --hard sha1
or
git checkout sha1

then git log does not show anything beyond that commit. It does give
some warning and recommend -b switch next time.  If I only do that by
accident or ignorance.  How to revert to the original HEAD?

-- 
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
唐詩274 韓翃  寒食
    春城無處不飛花  寒食東風御柳斜  日暮漢宮傳蠟燭  輕煙散入五侯家

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

* Re: can git reset or checkout be reverted?
  2009-02-06 14:19 can git reset or checkout be reverted? bill lam
@ 2009-02-06 14:43 ` Matthieu Moy
  2009-02-06 14:47 ` Jakub Narebski
  2009-02-06 16:03 ` Sitaram Chamarty
  2 siblings, 0 replies; 5+ messages in thread
From: Matthieu Moy @ 2009-02-06 14:43 UTC (permalink / raw)
  To: git

bill lam <cbill.lam@gmail.com> writes:

> If I want to recall a old version of testing by
>
> git reset --hard sha1

git reset is mostly about changing the place the current branch points
to. If you checkout branch master, and then say "git reset --hard
sha1", then, you say "OK, from now, the tip of branch master will be
sha1".

> git checkout sha1

This is the one you were looking for.

> then git log does not show anything beyond that commit. It does give
> some warning and recommend -b switch next time.

It does not "recommand" it, it says that _if_ you wanted to create a
branch, you could have done it with -b.

> If I only do that by accident or ignorance. How to revert to the
> original HEAD?

Case 1: you used checkout. Then, the branch still points to where you
were before the "checkout". Just "git checkout master", or replace
master with where you used to be.

In any case: the reflog can help you. It keeps track of where your
HEAD and other references (branches, ...) have been pointing before.

git reflog
git reflog show master

to see it, and this allows you to say things like

git checkout HEAD@{1}
git reset HEAD@{1}

The HEAD@{1} means "where HEAD used to be one move ago".

-- 
Matthieu

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

* Re: can git reset or checkout be reverted?
  2009-02-06 14:19 can git reset or checkout be reverted? bill lam
  2009-02-06 14:43 ` Matthieu Moy
@ 2009-02-06 14:47 ` Jakub Narebski
  2009-02-06 16:03 ` Sitaram Chamarty
  2 siblings, 0 replies; 5+ messages in thread
From: Jakub Narebski @ 2009-02-06 14:47 UTC (permalink / raw)
  To: bill lam; +Cc: git

bill lam <cbill.lam@gmail.com> writes:

> If I want to recall a old version of testing by
> 
> git reset --hard sha1
> or
> git checkout sha1
> 
> then git log does not show anything beyond that commit. It does give
> some warning and recommend -b switch next time.  If I only do that by
> accident or ignorance.  How to revert to the original HEAD?

  git checkout ORIG_HEAD

or

  git checkout HEAD@{1}

You can check it out wrt. second form using "git reflog" ("git log -g").

-- 
Jakub Narebski
Poland
ShadeHawk on #git

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

* Re: can git reset or checkout be reverted?
  2009-02-06 14:19 can git reset or checkout be reverted? bill lam
  2009-02-06 14:43 ` Matthieu Moy
  2009-02-06 14:47 ` Jakub Narebski
@ 2009-02-06 16:03 ` Sitaram Chamarty
  2009-02-07  5:31   ` bill lam
  2 siblings, 1 reply; 5+ messages in thread
From: Sitaram Chamarty @ 2009-02-06 16:03 UTC (permalink / raw)
  To: git

On 2009-02-06, bill lam <cbill.lam@gmail.com> wrote:
> If I want to recall a old version of testing by
>
> git reset --hard sha1
> or
> git checkout sha1
>
> then git log does not show anything beyond that commit. It does give
> some warning and recommend -b switch next time.  If I only do that by
> accident or ignorance.  How to revert to the original HEAD?

As others have said: reflog.

I just wanted to add, I've had a lot of luck using reflog's
@{now} feature:

    git reflog show @{now}

Coupled with a vague recollection of what action I did at
what time, this has saved me a few times, and if I've been
jumping around branches as well, then:

    git reflog show HEAD@{now}

Another good one is:

    git show-branch --sha1-name -g=5

(or some larger value depending on how big your xterm is.)
This is particularly useful when I've done a lot of 'git
commit --amend' or rebases; the top most '+' sign in each
column, starting from the left, is your reflog -- I don't
know who came up with this design but it's amazing how much
useful information is condensed into that display.

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

* Re: can git reset or checkout be reverted?
  2009-02-06 16:03 ` Sitaram Chamarty
@ 2009-02-07  5:31   ` bill lam
  0 siblings, 0 replies; 5+ messages in thread
From: bill lam @ 2009-02-07  5:31 UTC (permalink / raw)
  To: Sitaram Chamarty; +Cc: git

Sitaram Matthieu Jakub

Many thanks for help!

-- 
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
唐詩281 劉禹錫  春詞
    新妝宜面下朱樓  深鎖春光一院愁  行到中庭數花朵  蜻蜓飛上玉搔頭

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

end of thread, other threads:[~2009-02-07  5:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-06 14:19 can git reset or checkout be reverted? bill lam
2009-02-06 14:43 ` Matthieu Moy
2009-02-06 14:47 ` Jakub Narebski
2009-02-06 16:03 ` Sitaram Chamarty
2009-02-07  5:31   ` bill lam

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