3

While reading some tutorials/stackoveflow content, I read that conflicts can also occur with stash and apply.

For example: (From git-scm/git-apply---3way

-3

--3way

When the patch does not apply cleanly, fall back on 3-way merge if the patch records the identity of blobs it is supposed to apply to, and we have those blobs available locally, possibly leaving the conflict markers in the files in the working tree for the user to resolve. This option implies the --index option, and is incompatible with the --reject and the --cached options.

Is When the patch does not apply cleanly equal to getting conflicts?

How can we get conflicts not from merging operations? Are those conflicts any different then merge conflicts? I would love to see some graph examples.

Community
  • 1
  • 1
Stav Alfi
  • 13,139
  • 23
  • 99
  • 171

1 Answers1

3

Is When the patch does not apply cleanly equal to getting conflicts?

No: it is not applied "cleanly" when it cannot find the "context" of a hunk (set of lines on a patch) in the target file (the one where you apply the patch).
A patch is using "context diffs" and "unified diffs" (also known as "unidiffs"), which surround each change with context lines (lines that are supposed to be before and after the modification to apply), as well as range (line number where the modification occurs). A patch can then use this "context" to locate the region to be patched even if it has been displaced by changes earlier in the file, using the line numbers in the diffs as a starting point.

But if the modifications of the target do interfere with the patch (meaning: if the context is no longer there in the target file, because of modified or deleted lines), then it (the patch) does not apply cleanly.

How can we get conflicts not from merging operations?

You only get merge conflict when switching to a 3-way merge.
In that case, you have a common ancestor which gives you the ability to know whether or not a chunk is a change from the origin and whether or not changes conflict.
See more on the three-way merge in "Guiffy SureMerge - A Trustworthy 3-Way Merge".

https://www.guiffy.com/images/3waydiag.jpg

Rob Bednark
  • 25,981
  • 23
  • 80
  • 125
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks for the quick answer. I will love to get 3 clarifications from you: (1) What does it mean: "hunk contexts are not located in order"? (2) I thought a patch in Git is only the diff between 2 commits. what does it mean: A patch ... locate the region to be patched? (3) What does it mean: "modifications of the target do interfere with the patch" ? – Stav Alfi Nov 07 '17 at 21:43
  • 1
    @StavAlfi (1) not "in order", but "in order to": I meant "when the hunks of text cannot be found ("located") at their expected spot" – VonC Nov 07 '17 at 21:45
  • 1
    @StavAlfi (2) See https://en.wikipedia.org/wiki/Diff_utility#Unified_format: a patch has line numbers to help locate the place where it should be applied in the target file. – VonC Nov 07 '17 at 21:46
  • 1
    @StavAlfi (3) What the picture shows: the lines before/after the patch can have been moved or deleted in the target file, making applying the patch impossible. That is where a 3-way merge is useful, in order to compare those moves/deletion to a common ancestor. – VonC Nov 07 '17 at 21:48
  • (1) -> Hunks include the context. so theoreticly, if I will use less lines for context there is a better chance for the pth to apply cleanly. Or even better - 0 lines for the contex, will the path apply cleanly? – Stav Alfi Nov 07 '17 at 21:51
  • 1
    @StavAlfi No, it needs a context to know where to be applied. – VonC Nov 07 '17 at 21:52
  • (1) so who is trying to apply the path, completely ignore the `@@ -1,8 +1,9 @@` part? – Stav Alfi Nov 07 '17 at 21:57
  • 1
    @StavAlfi (1) not sure what you are asking, but you cannot "completely ignore" the rage information (`@@ -1,8 +1,9 @@`) – VonC Nov 07 '17 at 21:59
  • (1) "A patch can then use this context to locate the region to be patched even if it has been displaced by changes earlier in the file, using the line numbers in the diffs as a starting point." - I just checked it, it completely ignore the range infomration. Can you confirm also? – Stav Alfi Nov 08 '17 at 20:17
  • Yes, if the context matches, the range becomes optional – VonC Nov 08 '17 at 20:18
  • Well thanks for all the information and the additional help! I did learn alot from you. Maby it's only me but your replies helped me understand better then your original answer. Do you mind to edit your answer to contain most of your replies? Thanks alot agian! – Stav Alfi Nov 08 '17 at 20:21