Reputation: 3649
Obviously when a rebase occurs, it's possible for the committer information to change. What's the best way to preserve committer information (user.name, user.email) on a rebase?
I've tried getting the committer information with git log -1 --format="%cn
and git log -1 --format=%ce
, then setting that to my user.name/user.email and rebasing. That should be good enough right or am I missing something?
Upvotes: 9
Views: 3335
Reputation: 66
You can first do the rebase like normal and then use git filter-repo in a second run to set the committer of each commit to that commit's author:
git filter-repo --commit-callback '
commit.committer_name = commit.author_name;
commit.committer_email = commit.author_email;'
It is also possible to use git filter-branch for this task though this is discouraged and much much slower than git filter-repo:
git filter-branch --commit-filter '
GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME";
GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL";
git commit-tree "$@"' HEAD
Upvotes: 5
Reputation: 1282
I have a similar problem. Our core code repository has grown too big, so I've used git filter-branch to break it up, but this creates lots of empty merge commits in the smaller repositories. In attempting to remove them I found git rebase messes up the COMMITTER_DATE and COMMITTER_NAME/EMAIL which means any branches I rebase, no-longer link back in to the commits they came from, even if nothing changed, which means I can get lots of branches, with identical commits that aren't the same any more.
What seems to be the case is that by accident or design, git rebase
is not the answer if you want to preserve all three GIT_COMMITTER
environment variables in commits, use git filter-branch
instead (which seems to essentially allow you to rewrite commits exactly, only changing the 1 thing mentioned in the commit). Sadly not as easy as git rebase -i
In my case, I'm trying to remove specific commits from history in a branch, or re-order commits.
Upvotes: 4
Reputation: 16131
What exactly are you trying to accomplish? I assume you're doing this to make a branch or set of commits look identical to another branch or set of commits. Rebasing will not create brand new commits since they're done at different times with a different committer. The SHA-1 hashes won't be the same unless you make everything (including metadata) identical to the original commits - and if you wanted to do that then you might as well use the original commits and not the rebased ones. So I don't think rebasing will get you what you need. After a brief google search, it seems like what you're trying to do isn't easily done, and probably for good reason. That would be my answer - don't do what you're trying to do, I don't know what benefit this would have.
If you still want to investigate, I'd look into Environment Variables where you can set GIT_COMMITTER_NAME
and GIT_COMMITTER_EMAIL
, though I'm not exactly sure if you can easily set these on a commit-by-commit basis during rebase.
Upvotes: 2