Skip to main content Link Menu Expand (external link) Document Search Copy Copied

Blaming a Commit

Header Image

Ahoy there, matey! Have you ever found yourself in a situation where you need to figure out who made changes in a specific commit? Fear not, for we have just the tool for you - git blame.

git blame is a handy tool that allows you to see who made changes to a file and when. This can be useful when trying to track down who introduced a bug or when trying to understand why a certain change was made.

Using Git Blame

To use git blame, simply run the command followed by the filename you want to investigate:

git blame filename

This will display the contents of the file, along with the commit hash, author, and timestamp for each line. Here’s an example of what the output might look like:

abcdefg1 (Captain Hook  2022-04-01 10:00:00 -0500 1) # This is an example file
abcdefg1 (Captain Hook  2022-04-01 10:00:00 -0500 2) 
hijklmn2 (Blackbeard   2022-04-02 11:00:00 -0500 3) print("Ahoy, matey!")
abcdefg1 (Captain Hook  2022-04-01 10:00:00 -0500 4) 
hijklmn2 (Blackbeard   2022-04-02 11:00:00 -0500 5) print("Shiver me timbers!")
abcdefg1 (Captain Hook  2022-04-01 10:00:00 -0500 6) 

In this example, we can see that Captain Hook made changes to lines 1, 2, and 4, while Blackbeard made changes to lines 3 and 5. We can also see the commit hash, author, and timestamp for each line.

Conclusion

And there you have it, me hearty! git blame is a powerful tool that can help you track down who made changes in a specific commit. With this tool in your arsenal, you’ll be able to quickly identify who to blame for any bugs or changes you encounter.

But wait, there’s more! Be sure to check out our other articles on Git, including how to initialize a repository, add files, and create branches. Keep sailin’ the high seas of code, matey!