Okay, one sinister trick I've recently learned in git is to commit something "for" someone else. Sometimes, that's literally what I need to do. I had a case recently where a coworker was, for whatever reason, having a hard time committing, but he sent me the code directly. So I looked up if I could check it in for him myself and still have his info pop up if someone git blame-d the file.
 
git commit --author="Author Name <email@address.com>"
Even better, I don't even need to enter all that author info if the author has commited before:
git commit --author="Pat"
But which Pat is going to be used?
 
You can find out with this command
git rev-list --all -i --author=Pat
That will give you a list of commits by that author. The author for the most recent one in the list is the author that'll be used if you use that string (here Pat) in your git commit command.
 
My favorite use now is when I prettier a file, I can do so without overwriting ownership [if the file was [even mostly] written by a single author]. Usually I'd churn the whole file simply because of whitespace and look like I was own the hook for the whole thing. Now I can give that credit where it, um, belongs.
 
I think there's a way to log and maybe even blame files in git that ignores whitespace, but until I dig that back up, this is pretty useful.
 
(Note that it's not all ninja like. There is a "Committed by:" line registered in git that says you did it. But that takes some sluething and is totally fair.)

Labels: ,