title: Git Merge - Incomplete, Missing files and Folders
body: <p>I was trying to merge a dev branch into master.</p>
  
  <pre><code>git checkout master    
  git pull . dev
  </code></pre>
  
  <p>Everything seemed to go well, although there were conflicts I fixed these and commited. But when I checked this newly merged working tree is missing a lot of folders and files from dev.</p>
  
  <pre><code>git status  // Shows conflicts &amp; doesn't list some files/folders.    
  git commit -a 
  
  Created commit 55ffdd1: Merge branch 'dev' into master  
  
  git diff dev --name-status
  </code></pre>
  
  <p>Produces:</p>
  
  <pre><code>D       folders/lm.gif
  D       folders/lmh.gif
  ...
  </code></pre>
  
  <p>So the files/folders that didn't show up on 'git status'. It also didn't show up at the end when I fixed the merged conflicts.</p>
  
  <p>Also when I try to merge again it says:</p>
  
  <pre><code>git merge dev    
  Already up-to-date.
  </code></pre>
  
  <p>Yet the master branch clearly is missing files/folders from the dev branch. Why is that? Shouldn't that folder and all it's contents be added? 'folders' is being tracked on the dev branch, so shouldn't it have gotten pulled over when I did the merge?</p>
  
  <p>When there was a merge conflict earlier did git stop the merge process and skipped a bunch of files/folders?</p>
  
  <p>The dev branch had quite a lot of changes, could I have messed something up with git in the past that now certain files/folders wouldn't have merged?  </p>
  
  <p>(When I first created the dev branch I didn't know what I was doing and did crazy things like reset, reverts etc.)</p>
  
  <p>Hoping one of you git guru's here on stack overflow knows the answer. :) </p>
  
  <p>Thanks,
  Quang</p>
  
  <hr>
  
  <h2>Answer</h2>
  
  <p>Thanks Walter, Yes this is what happened.</p>
  
  <p>After doing some investigating I found out it was a little complicated what happened. It turned out that.</p>
  
  <ol>
  <li>dev branched from master, it had all the files.</li>
  <li>A third branch, lets call it "cleaned", branched off of dev.</li>
  <li>cleaned branch deleted all the files.</li>
  <li>cleaned branch merged (or something?) with master. At this point the files were deleted off of master. And the 'cleaned' branch disappeared.</li>
  <li>on dev, the files are still there and I continued adding to this branch, editing files for quite some time.</li>
  <li>dev merged with master and all the files that was deleted previously by cleaned were gone.</li>
  </ol>
  
  <p>Hope this helped someone besides me who learned quite a lot about how to use git log, git show, git reflog trying to debug what happened.</p>
  
  <p>Thanks!</p>
  
  <h2>How to Fix</h2>
  
  <p>So this is what I did to merge all of the contents in dev that was previously deleted back onto master.</p>
  
  <ol>
  <li>Got all the files/folders that was deleted (on dev but not on the newly merged master) <code>git diff dev --name-status | grep D &gt; deleted_files</code></li>
  <li>Output list of all files and folders <code>git log --name-status &gt; file_history</code> Gonna be using this to figure out the last updated version of the deleted file.</li>
  <li>Go through the list of deleted_files one by one, find the the most updated version in file_history and restore it. Example: <code>git checkout 25b8a44 view.php</code> 25b8a44... was the commit with the last updated version of view.php. I tried <code>cherry-pick</code> and just a straight <code>git checkout dev view.php</code> but i found explicitly using the commit id, it merge more of it's history. (Including the commit that cause the file to be deleted in the first place.)</li>
  <li>Once all the deleted files are back a quick check <code>git diff dev --name-status | grep D</code> shows that all files are copied over. Then like Walter said an ammend commit <code>git commit --amend</code> :)</li>
  </ol>