Tuesday, June 30, 2009

Git Pickaxe

Junio Hamano:

We would want to find the commit that changed the contents of the file to make this block of code into its final shape. […] Note that we are not interested in commits for which “git show” output contains the given string. We are only interested in a commit whose tree has this string in the file literally, but whose parent’s tree does not. In other words, we do not have to (nor want to) run textual diff and grep in the result. We count the number of occurences of the given string in the file in the tree of the commit, and the same for the commit’s parent. If we get different number, the commit chnages the string, which is what we wanted to find. Counting occurrences of substring is much cheaper than first generating textual diff and grepping in it (which is not what we want to do anyway).

Comments RSS · Twitter

Leave a Comment