-1

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 ?

Daniel
  • 2,355
  • 9
  • 23
  • 30
demonslayer1
  • 741
  • 2
  • 16
  • 24
  • Can you clean your question (remove the lorem ipsum stuff)? Instead of that post the file with the conflict content. – andzep Jan 10 '19 at 00:18

2 Answers2

0

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

progmatico
  • 4,714
  • 1
  • 16
  • 27
0

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.

jthill
  • 55,082
  • 5
  • 77
  • 137