Git Pills – Look for changes made on a specific file

With this pill you will learn a way to search for commits that contains changes to a particular file.

Yesterday I found myself in need to add some tags to a C# project I forked on BitBucket; the project is NTwain, a pretty good library that let you interface document scanning devices.

I need this because releases made by the original author has not been tagged in the past, so for me is now difficult compare changes happened from a revision to another.

In a C# project, you know, the version is written in an AssemblyInfo.cs file, so I thought: “If I find all the changes occurred in that file, I will find the commit to tag“.

The way to look for changes in a file is quite simple, using the git log command:

So my Git command was this:

Mmm… Changes are not many, there’s something strange; let’s open that .cs file.
I immediately realized that there was something strange because I did not find assembly version attributes; the author put them in the custom VersionInfo.cs file.
No problem, git log that file! But wait: what if that file has changed name in the past?

To be sure to look at all the changes occurred, you can use the good ––follow option:

This option accounts for file renames, so it guarantees taht you will not miss a single change happened to it.

Now that I have all the commit hashes of interest, I can conclude my work using the git tag command:

That’s all, hope this help :)
Please drop me a comment for feedback and suggestions.

Nando :)

Leave a Reply

Your email address will not be published. Required fields are marked *