title: How can I detect copy & pasted code using git?
body: <p>I just read the <a href="http://kernel.org/pub/software/scm/git/docs/git-blame.html" rel="noreferrer">git-blame</a> manual page once more and noticed this part:</p>
  
  <blockquote>
    <p>A particularly useful way is to see if an added file has lines created by copy-and-paste from existing files. Sometimes this indicates that the developer was being sloppy and did not refactor the code properly. You can first find the commit that introduced the file with:</p>
    
    <p>git log --diff-filter=A --pretty=short -- foo</p>
    
    <p>and then annotate the change between the commit and its parents, using commit^! notation:</p>
    
    <p>git blame -C -C -f $commit^! -- foo</p>
  </blockquote>
  
  <p>This sounds quite interesting, but I don't quite grok how it works, and why. I wonder whether it can be used in a git hook to detect copy &amp; pasted code.</p>
  
  <p>Can some git expert maybe explain the effect of using the above git commands together, and whether it's possible to use something like that to make git show whether there's code duplication (maybe by using the 'similarity index' which git seems to computed when renaming files)?</p>