2

I think I made a real mess in my GIT.

Here ist the situation:

enter image description here

The top most item (unveröffentliche...) is a working directory with some pending changes. I don't need them.

I just want to get back to the marked point, the commit from 5.Jun.

I would like to get rid of the detached head and this small branch and finally have master where HEAD is currently pointing.

jub0bs
  • 60,866
  • 25
  • 183
  • 186
Aleks
  • 5,674
  • 1
  • 28
  • 54
  • possible duplicate of [How can I rollback a github repository to a specific commit?](http://stackoverflow.com/questions/4372435/how-can-i-rollback-a-github-repository-to-a-specific-commit) – Roland Smith Jun 07 '15 at 13:54
  • possible duplicate of [Revert to a previous Git commit](http://stackoverflow.com/questions/4114095/revert-to-a-previous-git-commit) – Joe Jun 07 '15 at 16:09

3 Answers3

6

Method -1 :

Follow the below steps:

1. Right-click on the last good commit.
2. Select "Reset current branch to this commit".
3. In the dialog that comes up, select the "Hard" option.

Using this will reset your HEAD to that point permanently. All the commits above that point will be lost.

Method -2:

Using Terminal option

You can use reset command to reset your HEAD to that commit.

git reset --hard <commit_id>

git reset --hard 992d232  # By finding from the image attached.

To push the changes onto remote repository, use the below command. -f will forcibly push your local branch onto remote.

git push -f origin branch

Also on a general note, the command below will reset the HEAD to n commits back the current point.

git reset --hard HEAD~n

P.S. - Be careful when doing this. In a environment where you are working with others on a project, this will rewrite the project's history.

Rahul Gupta
  • 46,769
  • 10
  • 112
  • 126
0

Is really simple, if you don't want to save anything of your work just use:

git reset --HARD HEAD~(number of commits to rollback)

In your case should be something as:

git reset --HARD HEAD~2

Just remember that after this you need to force your push to your remote branch. Otherwise it will fail.

git push -f origin master
Oscar
  • 61
  • 5
0

This is a very common problem. Something that everyone has to face at one point or another. Whenever you have to check the previous states and revert to some particular previous state, just do the following.

git reflog

This will give a list of all the commits/state changes.

git reset --hard HEAD~n

This will take you back to the state you wish to go.

Monir Hadji
  • 119
  • 3
  • 11
Animesh Sharma
  • 3,258
  • 1
  • 17
  • 33