-1

So I'm just starting to learn git and I'm completely new to command line so struggling a bit.

So far I've learnt the simple things. Initializing, staging changes and then committing changes. Then I pushed all my changes to GitHub.

Now what I want to learn is going back to previous commits in git. So my test project currently has two commits and I want to go from 2 to 1. This is what I used to do that

git revert "my hash here"

This is what git returned:

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

Just wondering what this means and why it failed???

mikey
  • 3
  • 5
  • 4
    Did you *read* the message, and follow the hints? – poke Aug 11 '15 at 09:18
  • @poke well I'm currently trying to work out what they mean, that's why I posted it on here and of course I'm currently going through some tutorials to try and work out the answer. – mikey Aug 11 '15 at 09:21
  • You might want to take a look at [this](http://stackoverflow.com/questions/31922747/understanding-commits-in-git/31923288#31923288) – neshkeev Aug 11 '15 at 09:27
  • first clean your local working copy. `git checkout .` – khanmizan Aug 11 '15 at 09:28

2 Answers2

1

Going back to previous commit is not reverting - what you want is resetting. Try

git reset <your hash here>

And read also the documentation about revert and reset: git revert tutorial

Michael
  • 116
  • 6
  • I got the command I used of a tutorial that said it would work. Would it be possible for you to explain to me what is means by unmerged files – mikey Aug 11 '15 at 09:26
  • If you are trying to completely reset back to a previous commit and you *don't care about outstanding changes* and you are *willing to delete those changes without any chance of recovery* then you can use `git reset --hard ` to rollback your working copy to a previous commit. – tgharold Aug 11 '15 at 13:19
0

save unmerged files in stash, before revert.

git stash save

git revert a7da914393d0400f9a4eb77fd263e125a8ce7c57

git stash pop

unmerged files. maybe they are files in which unresolved conflicts occured while merging

irakli2692
  • 127
  • 2
  • 9