0

In a very simple example, I create a text file and add a line of characters then init add and commit. My file looks like this:

111

Then I add another line of characters add and commit, so my file looks like this:

111

222

Then I add another line of characters add and commit, so my file looks like this:

111

222

333

Then I revert ##########, referencing the second commit, where I added 222

In VSCode, I get a conflict to resolve and accepting incoming changes, I am left with:

111

I thought it should be:

111

333

Is this how revert works? Based on docs, it should remove just the changes from that commit, not all changes since then. Any ideas what I'm doing wrong?

Dave B
  • 21
  • 1
  • 5
  • 1
    `revert` creates a new commit that backs out the changes made in the referenced commit. (It reverses the patch). But you have a conflict. You need to resolve the conflict. – William Pursell May 24 '22 at 17:36
  • yes, but shouldn't the result be 111 333 (omitting just the changes in the specified commit)? – Dave B May 24 '22 at 17:44
  • 2
    You should resolve the conflict manually. By "accepting incoming changes," you are discarding the line you want to keep. – William Pursell May 24 '22 at 17:48
  • shouldn't the incoming changes only include the changes related to that specific commit (just the "222" line)? – Dave B May 24 '22 at 17:50

1 Answers1

1

Up to

In VSCode, I get a conflict to resolve

the answer to the question

Is this how revert works?

the answer is: Yes!

But

and accepting incoming changes

is not the typical conflict resolution. In fact, it is highly suspicious if a conflict resolution ignores one side entirely. (I'm not saying that it is always wrong, only that it is very atypical.)

In your case, the conflict looked like this:

111
<<<<<<
222
333
======
>>>>>>

It needs some thinking what needs to be done. Just clicking the "helpful" buttons in VS Code is rarely the correct thing. You must inspect what the reverted commit did and reproduces the inverse. In this simple case, you literally have to undo all the edits of the commit manually and do additional edits to arrive at

111
333

so that the git revert did not save anything (except that it wrote a clever commit message for you).

j6t
  • 9,150
  • 1
  • 15
  • 35