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.

3

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

-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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.