简体   繁体   中英

After reverting to an old commit, I can't go back to the most recent commit

I reverted my repo to an old commit, to see if a bug happens there.

I thought I did it with:

git checkout the_rev_number .

But judging by what's happening, I may have forgot the period at the end.

Now git log shows the same rev (as the one I reverted to) as the beginning (topmost item) of the log.

I tried git checkout . to revert to the most recent commit, but nothing changed. I also tried git reset --hard HEAD , but again, nothing changed.

Another clue : I may have done the initial revert while in a subdir, then tried to get back to the most recent commit while in the repo root.

What should I do?

When you did:

git checkout <SHA-1>

you checked out a previous commit in the detached HEAD state. There is nothing wrong whatsoever with this if you just want to poke around.

When you want to return to the HEAD of the same branch, the fix is surprisingly simple. Just checkout that branch again:

git checkout your_branch

In general, you don't need to worry about what you did in the detached HEAD state.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM