When working on a file, we often want to know who made certain changes last; we can use
git blame to see details about the last modification of each line in a file. In this lesson, we show and example of using
git blame to see who made the last change on a line in a file, and then we use the output of
git blame to use in other tools like
git log to see the full context of why the change was made and what other parts of the code base were effected at the same time as the line from
In our code editor, we're working on a file, and we'd like to know who last modified this line number one. We want to know why they added this export default. What we can do is let's go back to our command line, and let's run the git blame command with the name of our file, which was geturlslug.js.
When we run the git blame command, it shows us the details of how each line was last modified inside of the file that we passed in. In this case, for the geturlslug file, we have five lines in the file. For each line, we have the commit ID of when the line was last modified, as well as who last modified it, and when that change was made.
In this case, we know that the export default line change was made on July 2nd, and it was made by Trevor. This is the commit ID for that change. To get more context around this change, I like to copy the commit ID here, and then use other tools to find out more information.
For example, let's use the git log command to see more information about the rest of the changes in this commit. Now let's paste in the ID of the commit that we copied. Let's also use the patch option so that we see the diff.
Now we have the full context behind this commit. We see that the message was to upgrade to ECMAScript 2015 modules. We can see that there were other changes from the word function to export default, and that's been done throughout this commit on multiple files.