Why is git revert fail in this example?

The employee played with git revert today, he found himself in a strange situation:

git init echo 1 > file.txt git add file.txt git commit -m "Commit 1" # Say this generates hash aaa cat file 1 echo 2 >> file.txt git add file.txt git commit -m "Commit 2" # Say this generates hash bbb cat file 1 2 echo 3 >> file.txt git add file.txt git commit -m "Commit 3" # Say this generates hash ccc cat file 1 2 3 git revert bbb #line above does not work 

The refund does not work and ends with a cherry pick situation. I was expecting the following result:

 cat file 1 3 

diff -R works fine

 diff --git b/file.txt a/file.txt index aaa..bbb 100644 --- b/file.txt +++ a/file.txt @@ -1,2 +1 @@ 1 -2 

This is probably something really stupid, but what?

+5
source share
1 answer

This is just the opposite of a merger conflict. Conflict without unification? You can think of a return as the opposite of a merger. If you try to do the same in the opposite direction, you will get a merge conflict.

 $ git init Initialized empty Git repository in /home/depp/test/.git/ $ echo 1 > file.txt $ git add . $ git commit -m A [master (root-commit) 406d008] A 1 file changed, 1 insertion(+) create mode 100644 file.txt $ echo 2 >> file.txt $ git add . $ git commit -m B [master 730fed9] B 1 file changed, 1 insertion(+) $ git branch branch1 'HEAD^' $ git checkout branch1 Switched to branch 'branch1' $ echo 3 >> file.txt $ git add . $ git commit -m C [branch1 c359c04] C 1 file changed, 1 insertion(+) $ git merge master Auto-merging file.txt CONFLICT (content): Merge conflict in file.txt Automatic merge failed; fix conflicts and then commit the result. 

You might think the answer is β€œobvious”, and you can even file a bug or extension request with the help of the Git developers, but Git does not think the answer is obvious. Git thinks you should put "3" after "2", but now there is no "2", and therefore, where should you put "3"?

It is determined that Git will ask you for help if the context for a particular change does not exist, because these are cases where you may want to perform a manual installation.

Association pool?

I tried specifying merge=union in .gitattributes for file.txt , but this ended up returning nothing at all. Weird

+3
source

Source: https://habr.com/ru/post/1236393/


All Articles