Git revert last action
Asked Answered
U

2

6

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

Underbodice answered 3/2, 2017 at 15:11 Comment(1)
Everything you always wanted to know about git undo (but were afraid to ask): github.blog/2015-06-08-how-to-undo-almost-anything-with-gitForefinger
K
6

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) 
Kristofor answered 3/2, 2017 at 15:22 Comment(3)
I need a help.I was mistakenly fetch and checkout from different branch.But I have to go earlier branch with last commit..What shoud i do?Dd
@AHAMEDAAQIB If you have a different question from what is being asked here, you should post a new question.Kristofor
I posted the new question but no one didn't answer for that.Dd
L
1

@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

Legitimacy answered 17/2, 2017 at 21:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.