0

I have simple test repository - just 1 file and several commits (creation of the repository is described at the end). I'm trying two variants of cherry-pick operations and I don't understand logic of conflict resolution:

If I do: git cherry-pick test1

Git detects a conflict in string 1: 'change-1' <-> 'test-1'. It's clear.

If I do: git cherry-pick test2

Git doesn't detect a conflict and makes a new commit! It seems string 'test-1' is lost in this case.

I wonder why doesn't Git detect a conflict in the second case?


Creation of the repository

1.At the beginning I have an empty repositiory and one text file test.txt with the following content:

delimiter
footer

2.

git add test.txt
git commit test.txt -m 'v1'

3. test.txt is changed:

change-1
delimiter
footer

4.

git add test.txt
git commit test.txt -m 'v2'
git branch main HEAD

5.

git checkout HEAD^

6. test.txt is changed:

test-1
delimiter
footer

7.

git add test.txt
git commit test.txt -m 'v1_1'
git tag test1 HEAD

8. test.txt is changed:

test-1
delimiter
test-2
footer

9.

git add test.txt
git commit test.txt -m 'v1_2'
git tag test2 HEAD

10.

git.exe checkout main

The reporitory will look like:

v1_2 (tag 'test2')
 |
 |
v1_1 (tag 'test1')
 |
 |     v2 (branch 'main')
 |       |
v1--------

Then I do the first OR the second variant of cherry-pick.

avk700
  • 11
  • 2
  • How many branches do you have? – bichito Dec 30 '17 at 14:45
  • I have two chains of commits. One of them is a branch ('main'). Commits in the second chain marked by tags ('test1' and 'test2') – see the repository enclosed. – avk700 Dec 30 '17 at 15:02
  • as a general rule: do not post links. Post the graph of you branches – bichito Dec 30 '17 at 15:34
  • if you look at the tag docs they are ways of marking a commit. cherry pick docs only refer to branches, heads. "Two chains of commits" sounds like two branches. – bichito Dec 30 '17 at 15:51
  • changed the post – avk700 Dec 31 '17 at 12:09
  • Don't make changes so close to each other. Git doesn't look at individual lines, it looks at regions ("hunks") as changes. Try your example again making changes in different regions of a multi-line file. – Edward Thomson Dec 31 '17 at 14:08
  • Sorry but I get conflicts on both cherry-picks. Granted I did this in a rush, but it seems it should fail both times. Maybe somebody else can help you – bichito Dec 31 '17 at 15:02
  • @EdwardThomson I understand that if to try some other examples a conflict will be detected but I offered just this example and there are no conflicts. Honestly speaking I'm not sure it's safe to rely on Git functionality in operations of merge changes (cherry-pick, merge, rebase). It may be I don't understand something. – avk700 Jan 02 '18 at 11:42
  • @efekctive I get a conflict in the second case if I do merge instead of cherry-pick (git merge test2) but with cherry-pick – no conflict. – avk700 Jan 02 '18 at 11:49
  • I followed your step and I can't reproduce. Busy now :-} – bichito Jan 02 '18 at 16:44

0 Answers0