The -X option is no help here since the changes are on different lines. If we combine the two changes, the resulting code no longer compiles. In our version, we delete the unused variable to make a compiler warning go away-and in their version, they add a loop some lines later, using i as the loop counter. The base version might declare an unused variable: int i Just because our changes did not conflict on a line-by-line basis does not mean our changes do not actually conflict! One classic example occurs in languages with variable declarations. Since you said you are merging demo (theirs) into master (ours) and want the changes from demo, you would want -X theirs.īlindly applying -X, however, is dangerous. The -X ours and -X theirs options tell Git how to resolve this conflict, by picking just one of the two changes: ours, or theirs. Only if the changes are on the same lines, but are different changes, or that special case of interfering context, do you get a modify/modify conflict. If the changes happen on the same lines, but are identical changes, Git takes one copy of the change. If the changes happen on different lines-for instance, we change color to colour on line 17 and they change fred to barney on line 71-then there is no conflict: Git simply takes both changes. ![]() It's possible that things we changed are on different lines from things they changed, so that the changes seem like they would not collide, but the context has also changed (e.g., due to our change being close to the top or bottom of the file, so that the file runs out in our version, but in theirs, they have also added more text at the top or bottom). ![]() These changes are what you see in git diff output, and as always, they have context as well. Git has no real understanding of file contents it is merely comparing each line of text. These changes are (in general) found on a line-by-line, purely textual basis. Git has then found two sets of changes: "what we did" and "what they did". The "base" version is from the merge base between our commit and their commit, as found in the commit graph (for much more on this, see other StackOverflow postings). That is, the merge has identified three revisions (three commits): base, ours, and theirs. To understand what they do, though, you need to know how Git finds, and treats, merge conflicts.Ī merge conflict can occur within some file 1 when the base version differs from both the current (also called local, HEAD, or -ours) version and the other (also called remote or -theirs) version of that same file. As root545 noted, the -X options are passed on to the merge strategy, and both the default recursive strategy and the alternative resolve strategy take -X ours or -X theirs (one or the other, but not both). The most interesting part here is git merge -X theirs. ![]() Git push origin master # again, see below Git merge origin/demo # if needed - see below Git checkout demo # if needed - your example assumes you're on it Hence: git fetch origin # update all our origin/* remote-tracking branches You are doing three merges, which is going to make your Git run three fetch operations, when one fetch is all you will need. Not really related to this answer, but I'd ditch git pull, which just runs git fetch followed by git merge.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |