Here is what I've done:
I get in console:
error: could not revert a90deaf... first
hint: after resolving the conflicts, mark the
hint: with 'git add <paths>' or 'git rm <paths
hint: and commit the result with 'git commit'
Well, I would like to have all the files at the state of the previous commit, what should I do know?
UPDATE What I would want:
First, get back to a good state with:
git revert --abort
Next, look at what you're asking. git revert
takes the commit id of the commit you want to undo. The first commit sets a.txt
to be:
a
The second commit makes it have:
b
And you want to revert the first commit. So what that is saying is that you'd like to remove the addition of the a
line, and the addition of the file which is a conflict. The first commit added the file, and the second commit modified it. So git doesn't know what to do now that you're asking to remove it.
I assume by "all the files at the state of the previous commit" that you want to get back to the state where a.txt
has a
in it.
There are a couple of ways to get back to the previous state. If the commits have not been shared, you can simply use git reset
:
git reset --hard HEAD~1
This says "reset the state of my working copy and index to the previous commit". At this point, a.txt
will have a
in it.
If you had shared the second commit, then you don't want to do the above, because you'll be rewriting history, which causes a whole host of other issues. Instead, revert the commit, like you were trying to do above, but use the right commit. In this case, it's the HEAD commit you want to revert:
git revert HEAD
There are times when reverting a commit may conflict. In that case, it's very much like merge conflicts. You need to work through them, fixing up the conflicts and either using git add
to stage the file with the modifications, or using git rm
to remove the file. Once you're done, git revert --continue
will let the process finish.
The easiest way to go to restore the previous state, without having to do any fancy merging, is to use git checkout
. You can do:
git checkout HEAD~1 -- a.txt
git commit -m "Reverted to the previous version."
No merging, no fuss. :-) HEAD~1
can be any commit, of course. I just used this based on the example you had.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With