Going back to a previous commit in Gitkraken

Joymaker picture Joymaker · Aug 14, 2017 · Viewed 17.8k times · Source

My programming partner and I, being fairly new to Git and Gitkraken, made some mistakes, did some pushes pulls and commits in the wrong order, and got things fairly bungled up. I would like to go get a snapshot from several commits back, and manually compare it to the current state of the code. A command along the lines of

"Take the working directory state to this historic commit" or better yet, "give me the contents of this historic commit into a different working directory, which I will name"

The options given to me don't look that way, exactly. I see "reset master to this commit" in several flavors, but none of those titles convince me that I'm going to get to look at the previous state without damaging the path back to the current state. Am I missing something? What is the best way to do what I'm trying to do?

Answer

Christopher Díaz Riveros picture Christopher Díaz Riveros · Aug 15, 2017

I suggest you tu use git reflog, this command contains a local history of your commits and changes, with this log you will see all the events from your local repo.

After finding the exact commit that you want to recover, you can set that commit as starting point with git reset --soft HEAD@{n}

what --soft does is

Does not touch the index file or the working tree at all (but resets the 
head to <commit>, just like all modes do). This leaves all your changed
files "Changes to be committed", as git status would put it.

After this, you'll have all the changes in your stage area, then you can either decide if commit them again or change something.

I'd suggest you to read this section from Git's book and specially this section about undoing things.

PS. as an extra, you can use git reset as many times as you want, because all the commands that you use are saved in git reflog and because of that, if you do something that you don't want to, you can just undo it too.

Hope it helps