# can git reset or checkout be reverted?

5 messages from 2009-02-06 to 2009-02-07. Participants: bill lam, Jakub Narebski, Matthieu Moy, Sitaram Chamarty.
Thread: https://gitlist.dev/t/17610

## bill lam, 2009-02-06 14:19

Subject: can git reset or checkout be reverted?
Message-ID: <20090206141940.GB7231@b2j>
URL: https://gitlist.dev/e/20090206141940.GB7231%40b2j

```
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 韓翃  寒食
    春城無處不飛花  寒食東風御柳斜  日暮漢宮傳蠟燭  輕煙散入五侯家

```

## Matthieu Moy, 2009-02-06 14:43

Subject: Re: can git reset or checkout be reverted?
Message-ID: <vpqiqnnbp7x.fsf@bauges.imag.fr>
URL: https://gitlist.dev/e/vpqiqnnbp7x.fsf%40bauges.imag.fr
In-Reply-To: <20090206141940.GB7231@b2j>

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

```

## Jakub Narebski, 2009-02-06 14:47

Subject: Re: can git reset or checkout be reverted?
Message-ID: <m3vdrnvczd.fsf@localhost.localdomain>
URL: https://gitlist.dev/e/m3vdrnvczd.fsf%40localhost.localdomain
In-Reply-To: <20090206141940.GB7231@b2j>

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

```

## Sitaram Chamarty, 2009-02-06 16:03

Subject: Re: can git reset or checkout be reverted?
Message-ID: <slrngoonqk.urh.sitaramc@sitaramc.homelinux.net>
URL: https://gitlist.dev/e/slrngoonqk.urh.sitaramc%40sitaramc.homelinux.net
In-Reply-To: <20090206141940.GB7231@b2j>

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

```

## bill lam, 2009-02-07 05:31

Subject: Re: can git reset or checkout be reverted?
Message-ID: <20090207053137.GA7240@b2j>
URL: https://gitlist.dev/e/20090207053137.GA7240%40b2j
In-Reply-To: <slrngoonqk.urh.sitaramc@sitaramc.homelinux.net>

```
Sitaram Matthieu Jakub

Many thanks for help!

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

```
