0

I have client project where client gave access to me the Git repo (official), I'm doing the project along with my team mates (2~3 people) in a duplicated repo in different server. I'm able to sync between both repos, but when syncing the commits of unofficial repo to official repo git retains the contributor names. I do not want my client to know any other names in the commits except me.

For now, I ask my team mates in their respective branch, manually copy paste their changes to my branch and commit so commit goes by my name. I'm aware this is very illiterate way of using version control so looking for suggestion to streamline my flow so I can use standard git commands to achieve what I needed.

SenG
  • 713
  • 1
  • 7
  • 15

2 Answers2

1

When you get (git fetch) your collaborator commits, you can

The command:

git filter-branch --commit-filter \
'if [ "$GIT_AUTHOR_NAME" = "OldAuthor Name" ]; then \
export GIT_AUTHOR_NAME="Author Name";\
export GIT_AUTHOR_EMAIL=authorEmail@example.com;\
export GIT_COMMITTER_NAME="Commmiter Name";\
export GIT_COMMITTER_EMAIL=commiterEmail@example.com;\
fi;\
git commit-tree "$@"'

But that means you must not do any modification in that repo, as the filter-branch change its history.
You will use that repo only to push those modified commits to the client.
Internally, you are using your usual repos, synchronized with your teammates, where the real names are set on each commit.

Again, this solution is about having two different repos:

  • one which is shared with the team (no filter-branch there, git push/pull as usual, with the native author names used)
  • one for the client, which is fed by git cherry-pick and rewritten (filter-branch) before being pushed to the client.
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • That way the commit history would be tainted and it wouldn't be possible to synchronize the changes to customer repo to local repo anymore. – Zbynek Vyskovsky - kvr000 Feb 20 '16 at 07:53
  • @ZbynekVyskovsky-kvr000 it will be possible to synchronize changes to the customer as long as you are rewriting *new* commits that you import in the special repo and that you are pushing to the customer. – VonC Feb 20 '16 at 07:59
  • I think @ZbynekVyskovsky-kvr000 also wants to sync further changes by the customer onto their local repo (the one with the real names). In that case, he'd just have to `cherry-pick` the new customer commits onto their local repo. – David Deutsch Feb 20 '16 at 13:42
1

So VonC's answer is a good one, and I have upvoted it accordingly, but if you are interested in another approach, here is one way to go about it. It is a bit hacky, but hacky problems call for hacky solutions.

Have each developer put your name/email in their .gitconfig, so you are always the official author of each commit. Then, have each developer put the following script in their .git/hooks/post-commit file:

#!/bin/sh
git tag joe@blow.com/`git rev-parse --short head`

They will, of course, want to replace "joe@blow.com" with their own email address. When they push to your shared repo, they should pass --tags to git push, but when you push your customer's official repo, do NOT push the tags.

Now when you look at the history of your shared repo, you will see who committed what by the tag name. Most clients (like Source Tree) clearly show the tags associated with each commit, as does git log --decorate, etc.

David Deutsch
  • 17,443
  • 4
  • 47
  • 54
  • Provided that no-one does a `git commit --no-post-rewrite` (which bypasses the post-commit hook), that should work. +1. I still prefer my approach though ;) – VonC Feb 20 '16 at 16:37