tags:

views:

24

answers:

2

I'm working on a code base that's not mine for a project. I created a new git repo when I first started editing the code and probably touched a dozen or so files with new code since, making many commits.

What I would like to do is add a comment to the top of each change stating that I changed the code there, just for recording purposes. I was wondering if anyone knew of an easyish way to do this with git + scripts + magic dust, or if I'm going to have to do it manually. I can't think of anything myself.

+2  A: 

You already have a record that you changed the code. That's what your git repository is for. I find it annoying to see this kind of commenting when I look through others' source code.

Karmastan
+2  A: 

You already have that information recorded in your repository. Repeating that information creates a maintenance burden, and the likelihood of skew makes the annotations in your source untrustworthy.

Say the certain commit's SHA-1 is abc123, then you run

$ git diff --name-only abc123 HEAD

to see all the files that have changed since then.

If you're careful to keep the scope of each commit limited, then you can go back through the log and see changes in context, which is much more useful. To identify the commit that changed a particular line of a particular file, use git blame and then git show <SHA-1>.

To go from a different angle, view the output of git log -p to see commit messages along with their respective deltas. To see changes that introduce or remove particular strings, use pickaxe search with git log -S<string>.

Greg Bacon