Reputation: 1961
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
Upvotes: 3
Views: 21733
Reputation: 21
git log --all
will show you all your commits
you can git checkout the hash you want
Upvotes: 2
Reputation: 1961
Finally, with help of friends in here I come up with solution. the resean I post this. It may help other as well.
First, I used to git reflog
to show all my last commit.
Second, I used git checkout commit_id
Third, git log --graph --decorate --pretty=oneline --abbrev-commit master github/master temp
.
Then, git branch -f master temp
.
And, git branch -d temp
.
Finally, git push --force github master
Upvotes: 6
Reputation: 73936
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.
Upvotes: 4