0

I messed up badly my code and I want to revert it to the last commit.

I'm doing git status and I see that I changed a lot of files. I don't want to see them at all. So I did git log and found out the hash of last commit.

I used this hash in command: git fetch origin this_hash and got the message:

Mig-macbook-air:ios M$ git fetch origin this_hash
From https://github.com/linkto/myrepo
 * branch            this_hash -> FETCH_HEAD

but then when I do git status I still see broken files, also I see them in my IDE. I want to completely get rid of those changes, how can I do it?

I didn't do push on the last commit; I just created a branch and did a commit.

Chris Martin
  • 30,334
  • 10
  • 78
  • 137
user3766930
  • 5,629
  • 10
  • 51
  • 104
  • Did you read [How do you discard unstaged changes in Git?](http://stackoverflow.com/q/52704/218196) and [How do you undo the last commit?](http://stackoverflow.com/q/927358/218196) or [Revert Git repo to a previous commit](http://stackoverflow.com/q/4114095/218196) . If yes, why do these solutions not work for you? If no, why didn't you search first? – Felix Kling Feb 14 '16 at 00:53
  • 2
    Easy: https://xkcd.com/1597/ – Greg Valcourt Feb 14 '16 at 00:55
  • 1
    Possible duplicate of [git: undo all working dir changes including new files](http://stackoverflow.com/questions/1090309/git-undo-all-working-dir-changes-including-new-files) – Felix Kling Feb 14 '16 at 00:56

3 Answers3

2

If you see all the files when running git status, that means you have a lot of local changes that are not committed. If you are sure you want to get rid of those changes, run git reset --hard head.

David Deutsch
  • 17,443
  • 4
  • 47
  • 54
0

git fetch just fetches more commits from a remote; it doesn't touch the working directory.

You want git checkout <commit-reference>, which will check out that version into the working directory.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
-1

You have several options to do it:

Read here all about the several ways how to do it:
How to move HEAD back to a previous location? (Detached head)

Community
  • 1
  • 1
CodeWizard
  • 128,036
  • 21
  • 144
  • 167