title: Telling git to follow moved content (not simply moved files)
body: <p>While refactoring source code, sometimes you need to move big blocks of text inside a file, or even to a new file. You create a branch <code>refactored</code> and commit away:</p>
  
  <pre><code>$git checkout master
  $git branch refactored
  $git checkout refactored
  &lt;move code around&gt;
  $git commit -m "refactored code"
  </code></pre>
  
  <p>However, people may commit on top of the old pre-refactor branch, changing the code that was moved:</p>
  
  <pre><code>$git checkout master
  &lt;change code that was moved elsewhere on branch refactored&gt;
  $git commit -m "bugfix"
  </code></pre>
  
  <p>On branch <code>refactored</code>, you then want to incorporate changes made in <code>master</code>:</p>
  
  <pre><code>$git checkout refactored
  $git merge master
  &lt;giant merge conflict&gt;
  </code></pre>
  
  <p>This leads to a large merge conflict. If there was a way to tell git that the content was simply moved, it should be possible to merge automatically. </p>
  
  <p>The worse part is that, even after resolving the conflict and commiting it, git still can't use the resolution to figure out further merges:</p>
  
  <pre><code>&lt;fix conflicts&gt;
  $git commit -m "merge master into refactored"
  $git checkout master
  &lt;change more code&gt;
  $git commit -m "bugfix2"
  $git checkout refactored
  $git merge master
  &lt;another giant merge conflict&gt;
  </code></pre>
  
  <p>Is this avoidable at all? I've tried <code>git rerere</code> and it can't resolve the conflicts here. Is there any way git can see moving a block of text as a actual move, instead of a deletion and insertion? If it can't, what's the best approach to minimizing merge conflicts, if you need to keep the two parallel branches for a while?</p>
  
  <p>While this is easy enough for <a href="https://stackoverflow.com/questions/12785160/getting-git-to-follow-renamed-and-edited-files">moving the contents of a complete file</a>, I couldn't find information on moving only <em>part</em> of it, or moving inside the same file.</p>
  
  <p>Also, if there's a solution for this, what would be the behaviour of <code>git blame</code> on the refactored
  code? Would it point to the refactoring commit, or ignore it? Is there a way to achieve the later?</p>
  
  <p>In case anyone's interested, I've put a base64 encoded tar.gz of the (very minimal) repository I'm using for testing <a href="http://pastebin.com/raw.php?i=EwZtQf7R" rel="noreferrer">on pastebin</a></p>
  
  <h1>Potential Solutions</h1>
  
  <p>One potential solution might be performing the merge by applying a (automatically) edited patch with the changes in the pre-refactored branch. Is there software developed to do this? Using this approach I guess that, since this is transparent to git, <code>git blame</code> would point to the refactoring commit.</p>
  
  <p>I've found <a href="https://stackoverflow.com/questions/10066129/is-there-a-diff-like-algorithm-that-handles-moving-block-of-lines">the same question, applied to diff</a>. There's no mention to any existing non-proprietary implementation, but there mention to a algorithm that tracks block movement</p>