11

I'm trying to revert to a specific commit ( 3d5575f8e4c97ddab8ad5d540fee4664c04db75d ), but when i do:

git revert 3d5575f8e4c97ddab8ad5d540fee4664c04db75d

it says:

fatal: 'revert' is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm <file>' as
appropriate to mark resolution and make a commit, or use 'git commit -a'.

I don't care those changes, and I also want to lose those changes, revert to that commit (soft revert, dont want to lose the files) THEN repull down changes. My local stuff is all messed up. Any help?

sashoalm
  • 75,001
  • 122
  • 434
  • 781
Oscar Godson
  • 31,662
  • 41
  • 121
  • 201
  • 2
    I think `git revert` doesn't do what you think. It doesn't revert *to commit*. It creates new commit that reverts *a commit*. Do you want to lose all history between that commit and your current head or not? Does anyone else have a clone of that repo? – svick Nov 17 '11 at 02:35
  • should I do checkout? That also throws an error tho – Oscar Godson Nov 17 '11 at 02:36

2 Answers2

19

I think you want to use git reset 3d5575f8e4c97ddab8ad5d540fee4664c04db75d. This will keep your working files as is, but reset your HEAD to the commit you specified. Additionally, it should reset your index as well (clears out files you have selected to commit, add, remove, etc).

If you want to get rid of all the changes to your working files, use git reset --hard 3d5575f8e4c97ddab8ad5d540fee4664c04db75d.

DanR
  • 322
  • 2
  • 3
  • And for further reference on the different flavors of `reset` see Scott Chacon's post Reset Demystified (http://progit.org/2011/07/11/reset.html). – Sri Sankaran Nov 17 '11 at 03:03
3

You want to do:

 git reset 3d5575f8e4c97ddab8ad5d540fee4664c04db75d

This will "reset" you to the commit specify.

git revert just creates a new commit which reverts the changes of that commit, which is probably not what you want.

manojlds
  • 290,304
  • 63
  • 469
  • 417