31

My coworker (let's call him John here) and I work on a feature. and our working branch look like the following

--o--o--o # this is develop branch
   \   o--o--o # this is John's branch
    \ /       \
     o----o--o--o--o--o--o # this is our cowork branch
      \                 /
       o--o--o--o--o--o  # this is my branch

We've finished our work and are ready to merge our cowork to develop branch.

At this point, there are a lot of commits in the cowork branch, which is not expected to be seen by other developers. So I want to squash those commits into one commit.

But after squashing (resolving some conflicts), I've found that the author info all direct to me, there is no John's info.

So my question here is that is there some way to retain both John's and my info while combining those commits together?

Alex
  • 1,737
  • 2
  • 20
  • 35
  • The situation is slightly confusing to me. There are actually _two_ sets of merges if I am not mistaken, one where you and John merge into the `cowork` branch, and a second where `cowork` is merged into `develop`. Off the top of my head, you could rebase `cowork` on `develop` and then fast-forward the latter branch. – Tim Biegeleisen Sep 26 '16 at 10:22

2 Answers2

21

You can achieve something like this by using commit message conventions. Most git clients support this, including GitHub.

Specifically, add something like this to the end of your commit message:

Co-authored-by: John Smith <john.smith@example.com>

You can have multiple co-authors by including this line multiple times.

Will
  • 2,086
  • 23
  • 30
4

To be honest, git lacks the feature of adding multiple developer info to a single commit.

However, there are a few ways to get around it. As you will merge your changes from cowork branch to develop branch, it will create a Merge commit and before the merge you can do something like:

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

Please refer here for more info on workarounds for adding multiple developer info to a single commit.

Community
  • 1
  • 1
unrealsoul007
  • 3,809
  • 1
  • 17
  • 33