Home > other >  Why can't I revert a simple commit?
Why can't I revert a simple commit?

Time:01-28

I'm learnig GIT. I created a .txt file where I added three entries in the following order:

ABC
123
DEF

Each entry has been commited. Now, I would like to revert a commit where I added "123" to get the following effect:

ABC
DEF

or

ABC

DEF

But when I'm trying to use git revert <123 commit hash> I get an error. Does anybody know how to solve this problem?

MINGW64 ~/Desktop/GIT revert test (main)
$ cat file_1.txt
ABC
123
DEF

MINGW64 ~/Desktop/GIT revert test (main)
$ git log --oneline
6c358c2 (HEAD -> main) DEF added
e2dffa0 123 added
46abdb3 ABC added
39d0250 empty .txt file created

MINGW64 ~/Desktop/GIT revert test (main)
$ git revert e2dffa0
Auto-merging file_1.txt
CONFLICT (content): Merge conflict in file_1.txt
error: could not revert e2dffa0... 123 added
hint: After resolving the conflicts, mark them with
hint: "git add/rm <pathspec>", then run
hint: "git revert --continue".
hint: You can instead skip this commit with "git revert --skip".
hint: To abort and get back to the state before "git revert",
hint: run "git revert --abort".

MINGW64 ~/Desktop/GIT revert test (main|REVERTING)
$

Also, when I modified my file1.txt for the first time I got that message (maybe this will help):

warning: LF will be replaced by CRLF in file_1.txt. The file will have its original line endings in your working directory

CodePudding user response:

As the error states, the revert caused a merge conflict.

You need to resolve the conflict and then use git revert --continue to finalize the revert.

CodePudding user response:

You can read more about line breaks here. I think git is changing your line break after you commit and that is then causing a conflict on the revert. You can open the file to see what the conflict is about.

  •  Tags:  
  • Related