0

I'm writing a text file, its name "f2.txt". I did a commit for each line of the file. Its content would be:

l1
l2
l3
l4

In other words, it has four commits.

Each commit for each line.

So I tried to revert a commit. I get a conflict. Even tought I thought doing like that I wouldn´t get any conflict, cause it is a commit for each line. (Not the same line)

But yes, I do get conflict, even doing something simple like that.

What happens here?

Why I get conflict(s)?

Thanks.

Marcelo Noronha
  • 807
  • 2
  • 12
  • 26
  • 2
    Note that a revert is, in fact, a merge (with a funny merge base). See https://stackoverflow.com/q/47121793/1256452 – torek Oct 01 '18 at 18:20
  • @torek Can you spot the reason? – Marcelo Noronha Oct 01 '18 at 19:45
  • 2
    It's in [Igal S.'s answer](https://stackoverflow.com/a/52596463/1256452): the change you are reverting says "add a line at the end of the file" so the reversion is "delete that line at the end of the file", but *that* line is not at the end of the file any more. Git declares a merge conflict and leaves you to fix it. – torek Oct 01 '18 at 19:57

1 Answers1

1

I assume you have tried to revert a commit which was not the last one.

Conflicts happen when the context changes.

You have 4 commits:

  • Add l1 - new line to empty file
  • Add l2 - after l1 and before end of file
  • Add l3 - after l2 and before end of file
  • Add l4 - after l3 and before end of file

Now you try to revert the 3rd commit. Git is not sure what to do, it can see l2 which is before, but it is expecting end of file and instead you have l4.

It is obviously a bit more complicated than that. The patch command is smart enough to detect lines that moved and so on, but this is basically it.

Update

I don't really see any solution other than manually solve the conflicts.

You can read about merges and conflicts in git-tower

Igal S.
  • 13,146
  • 5
  • 30
  • 48