How do I add comments to all files changed since a certain commit?
For a project, I’m working on a code base that’s not mine. 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.
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>
.
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.
精彩评论