Today in our series on using Git in Eclipse we’re going to pursue a wacky idea in our Git Work project and return to our application state safely without any evidence of the changes we made on our adventure.
Before the Idea
We’re working in our issue-34 branch when the idea hits.
Before doing anything we’re going to commit our changes.
On Our Wacky Adventure
We follow that itch and begin by creating a wacky-idea branch.
While on our adventure we end up changing a couple of file/class names and renaming the package common to wackycommon.
Going Home Again
We gave it shot but decided the idea was just plain dumb. Never-the-less, the wacky code had some good things in it, so just in case we want to pull any code from it in the future, we’ll commit our wacky work.
You can see our “Wacky Work” commit in the Git Log list below. (Note: log-short is an alias I created to display commits on a single line.) Time to go back home again.
We could get rid of our wacky code altogether by resetting to our “Pre-Wacky Work” commit. We obtain the SHA-1 hash from the log (“ae0e3d6” shown above) and do a hard reset. This would do the trick but we’d not only lose our code in the working directory, but we’d lose our “Wacky Work” commit as well!
All we really have to do, since we’ve committed our work on our wacky-idea branch, is to checkout master where we’ll discover that it’s like our wacky coding adventure never happened!
So I guess with Git you CAN go home again…