title: Git Merge: parallel identical additions are merged without conflict by including the same code block TWICE in the merged file without complaint. Why?
body: <p>I have a slightly tricky history in my Git log that I am trying to understand fully.</p>
  
  <p>Before explaining the sequence of commits, let me paste images of the Git log (using SmartGit to visualize the history) for a file in question:</p>
  
  <p><img src="https://i.stack.imgur.com/tbRgu.jpg" alt="git_history_later"></p>
  
  <p>...</p>
  
  <p><img src="https://i.stack.imgur.com/IEEDN.jpg" alt="git_history_earlier"></p>
  
  <p>Shown is the Git history relevant to my question, with the irrelevant middle section snipped away.</p>
  
  <p>Two developers made code changes to the file in question, Developer 1 and Developer 2.</p>
  
  <p><strong>Developer 1</strong></p>
  
  <ul>
  <li>checks out the branch labeled '<em>origin/staging</em>' in the picture (but which was also '<em>origin/development</em>' at the time it was checked out)</li>
  <li><strong>adds a small code block</strong> (see below)</li>
  <li>commits and pushes - this push is labeled '<em>jon-dev-test-merge</em>', above</li>
  <li>makes a simple whitespace change to the code from the previous commit, and commits/pushes this whitespace change, labeled '<em>jon-dev-test-merge-2</em>', above</li>
  <li><strong>realizes he should have been working on a separate branch</strong>, so <em>starts over</em> and checks out '<em>origing/staging</em>' (at that time, '<em>origin/development</em>'), into a new branch called '<em>jons_dev</em>', which he pushes to, and sets up tracking for, on origin</li>
  <li>adds the same small code block (NOT including the whitespace change) to this new branch (blue line) (into a commit sometime before the one labeled '<em>test-merge-sales</em>')</li>
  <li>later, seeing that Developer 2 has made a change on the '<em>origin/development</em>' branch, merges '<em>origin/development</em>' into his '<em>jons_dev</em>' branch</li>
  </ul>
  
  <p><strong>Meanwhile...</strong></p>
  
  <p><strong>Developer 2</strong></p>
  
  <ul>
  <li>checks out the branch labeled '<em>origin/staging</em>' in the picture (but which was also '<em>origin/development</em>' at the time it was checked out)</li>
  <li>makes a code change to another file (completely unrelated to the code change from Developer 1, above) - this is in his working copy on his local development machine</li>
  <li>pulls Developer 1's code changes to the '<em>origin/development</em>' branch to his local machine and merges into a local-only branch/working copy; the merge succeeds without conflict.  Note that we don't see Developer 2's merge into his local branch (because he did not push that branch to the origin), but only the merge (see next bullet point) from his local branch back into what was the '<em>origin/development</em>' branch at that time.</li>
  <li>merges into the tracked development branch from origin on his local machine, and pushes the merge back up to origin - labeled '<em>vladimir-test-merge</em>', above</li>
  </ul>
  
  <p>So far, so good.</p>
  
  <p>Here is my question.</p>
  
  <p>In the process of understanding the sequence of events above, I noticed something odd - no changes from the '<em>origin/development</em>' branch <strong>for the file in question</strong> needed to be incorporated into the merge labeled '<em>origin/development</em>' - whose explanation turned out to be that in this file, <strong>the identical changes to this file, made in parallel, not including whitespace, were therefore present in both files</strong> so that just the changes from the '<em>jons_dev</em>' branch were required (and this is how the merge was performed).</p>
  
  <p>However, I noticed something from the merge, involving Git's method for merging and determining conflicts, that I cannot explain.</p>
  
  <p>To demonstrate the issue in the simplest way for my question, I first created the test branches indicated in the screenshots - '<em>test-merge-sales</em>', and '<em>jon-dev-test-merge</em>' / '<em>jon-dev-test-merge-2</em>'.  I then checked out the branch '<em>test-merge-sales</em>' and performed two separate merges into this branch (cancelling the merge in between the two tests).</p>
  
  <p>The relevant results from these two merges are shown below.  (Addendum: due to comments below the question, the second merge scenario is easily explained.  However, the FIRST merge scenario is still a question.)</p>
  
  <hr>
  
  <p><strong>(0) BASE file</strong></p>
  
  <p>Before showing a 3-way screenshot from the two merges, here is a screenshot of the relevant section of the file <strong>as it existed in the '<em>origin/staging</em>' branch BEFORE the branches diverged</strong>:</p>
  
  <p><strong>The base file:</strong>
  <img src="https://i.stack.imgur.com/PJHg6.jpg" alt="pre-branch-file"></p>
  
  <p>The image shows how the file looked for BOTH developers, BEFORE any changes were made by either developer.</p>
  
  <p>There are also comments present, which explain exactly what code changes were made by each developer to arrive at the pre-merge state shown in Case (1), below.</p>
  
  <p>As you can see from the comments, Developer 1 adds a function - <code>print_customer_part_order_history</code>, followed by a second function, <code>print_sales_analysis_page</code>, to a given spot in the file.  In parallel, the other branch has added to it a single function - <code>print_customer_part_order_history</code> - in exactly the same place in the file.  The code is identical, including whitespace.</p>
  
  <p>This is the state of the file moving into Merge Case (1), below.</p>
  
  <hr>
  
  <p><strong>(1) Merge from '<em>jon-dev-test-merge</em>' into the '<em>test-merge-sales</em>' branch</strong></p>
  
  <p><em>Note: This merge scenario is my main question.  Due to comments below the question, the question associated with the other merge scenario (#2, below) is already answered.</em></p>
  
  <p>This merge <strong>did not result in a conflict</strong>.  Opening a diff viewer for the merged file, here is a screenshot from the relevant (merged) lines:</p>
  
  <p><img src="https://i.stack.imgur.com/PrreP.jpg" alt="merge_from_jon-dev-test-merge"></p>
  
  <p>(Click this <a href="https://www.dropbox.com/s/1kwlj5rzoq55bk5/merge_from_jon-dev-test-merge.jpg" rel="noreferrer">link to full-size image</a>)</p>
  
  <p><strong>Note that Git merged the files by including BOTH identical functions (added in parallel) <em>'print_customer_part_order_history()'</em> - with no merge conflict</strong>.  (This is the code snippet that Developer 1 added, in parallel, to the two branches.)  Therefore, this function appears twice in the merged code.</p>
  
  <p>Note: the '<em>test-merge-sales</em>' branch has <em>the same whitespace</em> - leading spaces - in the highlighted code block in both branches.</p>
  
  <p>Question 1: Why did Git decide there was no merge conflict?  Two blocks of code were added in parallel at the same location in the file.  Even though the blocks of code are identical, I would think that this should be a merge conflict.</p>
  
  <hr>
  
  <p><strong>(2) Merge from '<em>jon-dev-test-merge-2</em>' into the '<em>test-merge-sales</em>' branch</strong></p>
  
  <p><em>Note: Due to comments below this question, the question associated with this merge scenario is already answered.</em></p>
  
  <p><img src="https://i.stack.imgur.com/nXegc.jpg" alt="merge_from_jon-dev-test-merge-2.jpg"></p>
  
  <p>(Click this <a href="https://www.dropbox.com/s/t4q70vhs4nhuff8/merge_from_jon-dev-test-merge-2.jpg" rel="noreferrer">link to full-size image</a>)</p>
  
  <p>The only difference in the code being merged is that Developer 1 changed leading spaces to tabs.  <strong>However, in this case, with only the whitespace difference, Git has declared there is a merge conflict</strong>.</p>
  
  <p>Question 2: Why - with only a difference in whitespace - would Git decide that in one case, there is no merge conflict, and in the other case, that there <em>is</em> a merge conflict?</p>
  
  <hr>
  
  <p>My two questions are identified above, regarding how Git handles merges and merge conflicts.</p>
  
  <p>Thanks!</p>
  
  <hr>
  
  <p><strong>ADDENDUM</strong>
  I have added an additional screenshot - the relevant text of the file <strong>BEFORE</strong> the two branches diverged - along with descriptive text, in the section called "<strong>(0) Base File</strong>".  Thanks!</p>