How to attribute a single commit to multiple developers?

47,844

Solution 1

Commit title

Commit body

Co-authored-by: name <[email protected]>
Co-authored-by: name <[email protected]>

One problem with this approach is that you can't create a signed key for this group of devs, so you could essentially add anybody to this list even if they didn't work on a feature and GitHub would treat it as if they did. However, this shouldn't be an issue in most cases.

e.g. Co-authored-by: Linus Torvalds <[email protected]>

With normal authors or signing groups (the old method) you would see it's not signed and know that you can't trust the commit. However, there is no signing process on co-authors.


Mostly outdated answer:

One solution would be to set a name for the pair:

git config user.name "Chris Wilson and John Smith"

Here is a related bug report with other temporary solutions:

Bug git-core: Git should support multiple authors for a commit

Solution 2

A git convention is to use Co-Authored-By at the end of the commit message (git kernel: Commit Message Conventions, referring to Openstack Commit Messages). This is also one of the solutions on the git-core bug linked in Gerry's answer

Co-authored-by: Some One <[email protected]>

In that comment on May 5, 2010, Josh Triplett also suggests implementing corresponding support in git.

As Llopis pointed out in a comment, GitHub announced support for this on their blog on Jan 29, 2018: Commit together with co-authors (details).

Solution 3

For Bazaar:

bzr commit --author Joe --author Alice --author Bob

Those names will be shown in the log separately from committer name.

Solution 4

git-pair

https://github.com/pivotal/git_scripts#git-pair

This simple script from Pivotal to automate Git pair programming attribution.

You create a .pairs file like:

# .pairs - configuration for 'git pair'
pairs:
  # <initials>: <Firstname> <Lastname>[; <email-id>]
  eh: Edward Hieatt
  js: Josh Susser; jsusser
  sf: Serguei Filimonov; serguei
email:
  prefix: pair
  domain: pivotallabs.com
  # no_solo_prefix: true
#global: true

and then:

git pair sp js

sets:

user.name=Josh Susser & Sam Pierson
[email protected]

for you.

Solution 5

git distinguishes between a commit's author and committer [1]. You could use it as a work-around, e.g. sign yourself as the committer and your co-author as the author:

GIT_COMMITTER_NAME='a' GIT_COMMITTER_EMAIL='a@a' git commit --author 'b <b@b>'

This way, both you and your co-author will be recorded in the git history. Running git log --format=fuller, will give you something like:

commit 22ef837878854ca2ecda72428834fcbcad6043a2
Author:     b <b@b>
AuthorDate: Tue Apr 12 06:53:41 2016 +0100
Commit:     a <a@a>
CommitDate: Tue Apr 12 09:18:53 2016 +0000

    Test commit.

[1] Difference between author and committer in Git?

Share:
47,844

Related videos on Youtube

Ciro Santilli OurBigBook.com
Author by

Ciro Santilli OurBigBook.com

反中国共产党常见问答集 Anti Chinese government FAQ | $ Sponsor Ciro $ | cirosantilli.com | OurBigBook.com | Necromancer #1 in 2019-07 | Linux Kernel Module Cheat | x86 Bare Metal Examples | Cool Data in the Bitcoin Blockchain | 2D Reinforcement Learning Game | Oxford Nanopore River Bacteria | ELF hello world | Articles | Cirism | Contact | Ukraine: 1) Putin bad, democracy less bad 2) USA has done similar: Iraq, Cuban Missile crisis, Monroe Doctrine, CIA backed dictatorships in Latin America and Middle East 3) Realpolitik view: https://www.youtube.com/watch?v=JrMiSQAGOS4 | https://www.youtube.com/watch?v=ZnHo6JXxcQM 4) Promise to stop NATO/EU expansion in Ukraine. Ukraine is not fundamental for West security, but is for Russia. Make a deal with the Devil. 5) Independence referendums on each Ukrainian Oblast 6) More nuclear power in Europe to reduce Russian gas dependency. https://cirosantilli.com/china-dictatorship/gay-putin https://cirosantilli.com/china-dictatorship/putler https://cirosantilli.com/china-dictatorship/alexei-navalny https://cirosantilli.com/china-dictatorship/putin-riding-things https://cirosantilli.com/china-dictatorship/belarus Как правильно сдаваться How to surrender https://t.me/s/rf200_now Найти пропавшего русского солдата Find missing Russian soldier Когда и где протестовать против войны When and where to protest against the war Main squares, 19:00 weekdays, 14:00 weekends. https://cirosantilli.com/china-dictatorship/tiananmen Freedom of speech posts https://meta.stackexchange.com/q/366163/200117 https://meta.stackexchange.com/q/361486/200117 See: https://github.com/cirosantilli/china-dictatorship/blob/master/stack-exchange-lost-freedom-of-speech.md

Updated on November 13, 2020

Comments

  • Ciro Santilli OurBigBook.com
    Ciro Santilli OurBigBook.com over 3 years

    The way all version control systems I'm familiar with work is that each commit is attributed to a single developer. The rise of Agile Engineering, and specifically pair programming, has lead to a situation where two developers have made a significant contribution to the same task, a bug fix for example.

    The issue of attribution won't be too much of a big deal in a work environment since the project manager will be aware of the work the pairs are doing, but what about if two open source contributors decide to pair up and push out some code to a particular project that has no idea they're working together. Is there any way for a version control system like Git to attribute a particular patch to multiple developers?

    • Ciro Santilli OurBigBook.com
      Ciro Santilli OurBigBook.com almost 10 years
      This should be split for each version control system.
  • ruslanys
    ruslanys over 7 years
    This is similar to the git convention Co-Authored-By I mentioned in a separate answer
  • llrs
    llrs over 6 years
    This is now supported by GitHub.
  • ruslanys
    ruslanys almost 6 years
    From what I can see, this is a git alias that adds "Co-authored-by: " plus the "co-author <co-author-email>" to the end of the commit message.
  • c--
    c-- over 5 years
    I wrote a simple git plugin to make it easier to manage these Co-authored-by trailers automatically: github.com/cac04/git-pair
  • Aaron Franke
    Aaron Franke about 5 years
    What about if you don't know the person's Email address? Any way to link GitHub username etc?
  • Gerry
    Gerry about 5 years
    If they made a previous commit you can just check that: git show <COMMIT_ID> --format=email
  • Meiogordo
    Meiogordo almost 5 years
    This seems to already be working in GitLab (see gitlab.com/gitlab-org/gitlab-foss/merge_requests/17919)
  • Ruslan
    Ruslan over 4 years
    This approach looks like a kludge (cf. the Bazaar way). And there's a principal author this way, to which the co-authors are just an addition, if I understand it correctly.
  • Csteele5
    Csteele5 over 3 years
    Excellent piece of code here, worked flawlessly and achieved the desired effect of having a specific co-author on my PR.