Note that there are some explanatory texts on larger screens.

plurals
  1. POgit merge: Removing files I want to keep!
    primarykey
    data
    text
    <p>How can you merge two branches in git, retaining <em>necessary</em> files from a branch?</p> <p>When merging two branches, if a file was deleted in one branch and not in another, the file is ultimately deleted.</p> <p>For example:</p> <ul> <li>A file exists in master when you make a new branch</li> <li>you remove the file from master since we don't need it (yet)</li> <li>you make changes in the branch to add a feature, <em>which relies on the file existing</em></li> <li><em>you make bug fixes in master</em> (cannot be discarded)</li> <li>you merge some day, and the file is gone!</li> </ul> <hr> <p>How to Reproduce:</p> <ol> <li><p>Create a git repo with one file.</p> <pre><code>git init echo "test" &gt; test.txt git add . git commit -m "initial commit" </code></pre></li> <li><p>Create a branch</p> <pre><code>git branch branchA </code></pre></li> <li><p>Delete the file in master</p> <pre><code>git rm test.txt git commit -m "removed file from master" </code></pre></li> <li><p>Make ANY changes in branchA that don't touch the deleted file (it has to be unchanged to avoid Conflict)</p> <pre><code>git checkout branchA touch something.txt git add . git commit -m "some branch changes" </code></pre></li> </ol> <p>From here, any way I've found to merge these two branches, the test.txt file is deleted. Assuming we were <em>relying on the file</em> for <code>branchA</code>, this is a big problem.</p> <hr> <p><strong>Failing examples:</strong></p> <p>Merge 1</p> <pre><code>git checkout branchA git merge master ls test.txt </code></pre> <p>Merge 2</p> <pre><code>git checkout master git merge branchA ls test.txt </code></pre> <p>Rebase 1</p> <pre><code>git checkout branchA git rebase master ls test.txt </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload