DEV Community

How to attribute another author when you're committing on git?

Salim MAHBOUBI on May 07, 2018

Why? You might find yourself in a situation where you have to commit some code that has been authored by someone else. They might not ha...
Collapse
 
jpgoldberg profile image
Jeffrey Goldberg

This is why we sign commits!

Collapse
 
ferricoxide profile image
Thomas H Jones II

We do signed commits, as well. Presumably, if you were wanting to do this type of thing (giving credit where credit's due), you'd want to disable signing for the commit.

That said, no matter who the original code-author is, (at least in our organization) if you push breakage into the project because you were effectively vouching for someone else's code, you'll get the blame. Similar rule applies to designated approvers that approve a merge to a protected branch.

Collapse
 
ztickm profile image
Salim MAHBOUBI

Oh this is great thanks!

Collapse
 
defman profile image
Sergey Kislyakov
Collapse
 
gedw99 profile image
Gerard Webb

This is just what I need but did not know was possible. Thanks Salim.

I am not very confident in my team and so if I can submit as a different person ( it's a really big company so will be cool ) and they hate my PR then nothing lost !!.ah but what if they like it ?
Ah it's a double edged sword this one ..

Collapse
 
ferricoxide profile image
Thomas H Jones II

Take note of the doubled commit-icon in the image-capture from the author's repository view. Git still knows who actually pushed the commite - eitehr via the SSH key used for the git@... URL, the credentials passed via the https://... URL or the API-token you used. So, you'll get this doubled icon when the author-tag doesn't match what's in the pusher's registered list of email addresses.

Also, (especially) if you're in a big org, you should probably be forcing commit-signing on your projects to help prevent attempts at game-playing.

Collapse
 
andy profile image
Andy Zhao (he/him)

Woah, that's pretty cool. Did not know that was a feature of git.

Collapse
 
ztickm profile image
Salim MAHBOUBI

Yeah it's really great. The contributors thought of a lot of cases that might not happen to everyone but are worth implementing in case we need it.

Collapse
 
sofianemias profile image
Sofiane

thanks bro !