Get files from previous git commit

375 views Asked by At

Sorry if this question sounds dumb.

So, I am following Michael Hartl's Rails Tutorial.

Up to the end of chapter 8, everything was work fine.

But I have made some mistakes during chapter 9 that I cannot figure out.

So, I would like to go back to the commit I did at the end of chapter 8, to get everything working again and start over from here.

In other words, I want to erase everything that has been done since that last commit and (re)start fresh at the beginning of chapter 9.

According to the log, here is the commit I need to "retrieve" files from:

Computer:microblog TXC$ git log
commit dd0d9e82e802b18e5ba1000eff743445183bcc56
Author: thibaudclement <[email protected]>
Date:   Wed Jun 24 18:02:13 2015 -0700

    Finish log in/log out

I tried to git checkout from the current updating-users branch and git delete the branch, I tried to git pull from the remote, and I tried to git reset hard to the desired commit (as explained here: How to revert Git repository to a previous commit?), but I could not get my local files to look like the ones at the end of chapter 8.

How can I simply get on my local repository the files from the Finish log in/log out commit mentioned above?

1

There are 1 answers

0
Rahul Roy On BEST ANSWER

In case git reset --hard commit_id isn't working, try following:

  1. Discard any unstaged changes using:

    git reset --hard

  2. Checkout to master branch

    git checkout master

  3. Remove topic branch "updating-users"

    git branch -D updating-users

  4. Recreate a branch for chapter 9

    git checkout -b "name-of-the-branch"

I'm assuming that you're merging your topic branches into master branch, after each chapter.