title: Git rewrite history move folders and files up to parent folders
body: <p>I want to rewrite history and move all files and folders in a certain folder 2 folders up for all branches.</p>
  
  <p>My repo looks like:</p>
  
  <ul>
  <li>src
  <ul>
  <li>v105</li>
  <li>src
  <ul>
  <li>files</li>
  <li>folders</li>
  </ul></li>
  </ul></li>
  <li>tools</li>
  <li>lib</li>
  </ul>
  
  <p>I want it to be:</p>
  
  <ul>
  <li>src
  <ul>
  <li>files</li>
  <li>folders</li>
  </ul></li>
  <li>tools</li>
  <li>lib</li>
  </ul>
  
  <p>I know how to rewrite history for removing files recursively in a folder</p>
  
  <p><code>
  git filter-branch --force --index-filter 'git rm -rf --cached --ignore-unmatched somefolder/somefolder'
  --prune-empty --tag-name-filter cat -- --all
  </code></p>
  
  <p>I also know the <code>git mv</code> command. </p>
  
  <p>Using the following command the files and folders are all moved to the correct folder. The first patterns matches all files and folders within the provided folder. The second pattern matches all files and folders starting with a dot.</p>
  
  <p><code>git mv src/v105/src/* src/v105/src/.[^.]* src</code></p>
  
  <p>However when I want to use this command with the rewrite history command it doesn't work.</p>
  
  <p><code>
  git filter-branch --force --index-filter 'git mv src/v105/src/* src/v105/src/.[^.]* src --cached --ignore-unmatched'
  --prune-empty --tag-name-filter cat -- --all
  </code></p>
  
  <p>Because the src folder does not exist in all cases in my commit history it tells me it can't find the src dir. Any ideas how to solve this?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p><code>
  git filter-branch --force --index-filter 'if [-d 'src/v105/'] then git mv src/v105/src/* src/v105/src/.[^.]* src fi'
  --prune-empty --tag-name-filter cat -- --all
  </code>
   results in unexpected end of file.</p>