O'Reilly logo

Pragmatic Version Control Using Git by Travis Swicegood

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Following Content

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required