As we talked about in Copying Files—or Not, Git can track when the content moves within a file and even when it moves to another file. This is useful when you’re trying to track down the original commit and author of a few lines of code.
To keep from matching lines like a closing bracket in C or a simple constructor in Python, Git tries to match at least three lines when it tries to detect a copy and paste.
Let’s create a new file to demonstrate this functionality. Call it original.txt, and put the following three lines in it:
This is the first line.
This happens to be the second line.
And this, it is the third and final line.
Once you’ve saved your new file, add it to the repository, and commit:
prompt> git add ...