I have a text file with the following content:
initially:
hello
first commit:
hello
asdfasdf
second commit:
hello
test
third commit:
hello
test
test2
Now I want to revert to the second commit , but I am getting a merge conflict why ?
I have a text file with the following content:
initially:
hello
first commit:
hello
asdfasdf
second commit:
hello
test
third commit:
hello
test
test2
Now I want to revert to the second commit , but I am getting a merge conflict why ?
Caution, the --hard
destructs the working folder files.
If you are in master branch, when at your third revision, you can do:
git reset --hard master~
This reverts to master ancestor revision, placing that revision both in the git cache and in the working folder.
You can now make changes again to the second revision in the working folder, add them, and proceed.
You probably didn't use any option, so git selected --mixed
, which reverts cache but not the working dir (but I am guessing what you did here)
Be careful before using --hard
, and apropos see also here
git revert
is a merge,
Init---first---second---third
of the changes from your reverted second
commit to its parent (i.e. delete line test
and replace it with asdfasdf
) with the change from your reverted commit to the current tip (add line test2
after line test
).
So in one set of changes you deleted a line, in the other you kept it and added more. The question Git is refusing to answer for you automatically is whether your added test2
line belongs with the test
line you replaced in the other changes.
Experience with lots and lots of changeset merging says adjacent lines are so often related that automatically accepting an additional line in one changeset adjacent to a line changed in another is a bad move, some human needs to decide what the right result should be.
When the changes are "obviously" not related, it can be hard to imagine why Git thought they might be, or even to see the adjacency at all, but that's what's going on here. You've found the case that's kind of a tossup, if it's easy for you to get it right, no big loss, just choose, it takes seconds.