Re: can git reset or checkout be reverted?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



bill lam <cbill.lam@xxxxxxxxx> 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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux