Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (29.3k points)

I sometimes check out some previous versions of the code to examine or test. I have seen instructions on what to do if I wish to modify previous commits -- but suppose I make no changes. After I've done e.g. git checkout HEAD^, how do I get back to the tip of the branch?.. git log no longer shows me the SHA of the latest commit.

1 Answer

0 votes
by (50.2k points)

If the commit (that you need to return) is known and you want that to attach with the head of some branch then use:

git checkout <branch-name>

And also you can see the commits that your HEAD has previously pointed to by using:

git reflog

For the latest versions of git, if you had done any checkouts something to moving your HEAD 

You can also do:

git checkout -

This will take you back to the previous checkout. Thus, you can go back to the latest commits after checking out a previous commit.

Browse Categories

...