简体   繁体   中英

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 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.

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> .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM