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?
What does it mean to squash commits in Git? Squashing is a way to rewrite your commit history; this action helps to clean up and simplify your commit history before sharing your work with team members. Squashing a commit in Git means that you are taking the changes from one commit and adding them to the Parent Commit.
Before you start, keep in mind that you should squash your commits BEFORE you ever push your changes to a remote repository. If you rewrite your history once others have made changes to it, you're asking for trouble… or conflicts.
As a general rule, when merging a pull request from a feature branch with a messy commit history, you should squash your commits. There are exceptions, but in most cases, squashing results in a cleaner Git history that's easier for the team to read.
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 <[email protected]>
You can have multiple co-authors by including this line multiple times.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With