In my previous post we went through branching in git and commands that can be used to get changes from one branch to another.
Oops!
Let us explore some commands that will prove useful when we end up in tricky situations with Git.
Reset
Reset helps you undo a commit. You know those times when you commit too soon.
Git offers you the following levels of control to when you attempt a reset.
Soft
Moves HEAD
to the commit you want to, with files after that point in the staging area
Mixed
Moves HEAD
to the commit you want to, with files in working area
Hard
Moves HEAD
to the commit you want to and removes files
git reset --hard cf23d45xsd
Oh no! Lost what I was doing
- Git
reflog
keeps track of all the changes you made to your repository- Useful in backtracking what happened
- Helps you get back to where you were
git reflog
You could then choose to reset to a particular commit in that output or just use the HEAD@{6}
that would help you to get your local repository to that exact point.
Try it.
This is the last of the Practical Git series posts.
I hope you enjoyed it.