'Git checkout to recent commit

I have a total of 24 commits, and I had checkout to commit 15. How can I go back to my last commit?

Note: I have run a lot of commits. For instances,

git revert, git checkout, git reset.

I don't know my last commit name, id, or even the files. All I know that I have committed, but I am not there.

but I could not go back to my latest commits.

Thank you

git


Solution 1:[1]

git checkout foo will check out the most recent commit on the foo branch. If you're working in master, you would run the command git checkout master.

Edit: In this case, you seem to have been committing to a detached head. You should follow the advice given for this question and avoid doing this in future.

Solution 2:[2]

git log --all will show you all your commits
you can git checkout the hash you want

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Community
Solution 2 user18234718