Git revert last action

13,232

Solution 1

It sounds like you're using some kind of GUI but you haven't specified which. If you want to jump back to a previous revision, you can use the following

git checkout HEAD@{1}

This goes back to the previous revision in the git reference log. However, you will be in a detatched HEAD state. This means any commits you have will not be associated with a branch and new commits from any branch will not be automatically pulled in. This is probably not what you want.

If you know which branch you want to be on, you can use

git checkout BRANCH_NAME

Alternatively, if you know you were on some branch but not sure which one, you should be able to get the name of the branch with

git name-rev $(git reflog --pretty='format:%H' -1) 

Solution 2

@Michael is right. Because you have switched to another commit, your are in a detached head. I will show how you can fix this in the GUI (TortoiseGit).

You could see that in TortoiseGit in the log, see the <no branch>

enter image description here

enter image description here

You get back to your original commit, just switch back to your branch, e.g master:

enter image description here enter image description here

Share:
13,232
Aldridge1991
Author by

Aldridge1991

Updated on June 06, 2022

Comments

  • Aldridge1991
    Aldridge1991 almost 2 years

    While trying to move to a previous commit, I did "Switch/Checkout", then selected the commit which I wanted to move to and then unchecked "Create New Branch" option.

    The movement was done fine but now i can't go back to the most up-to-date commit. Luckily I saved it on Bitbucket but I was wondering if this could be solved from local git.

    I use TortoiseGit