Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git rebase preserve committer

Tags:

git

rebase

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?

like image 417
solstice333 Avatar asked Apr 25 '26 11:04

solstice333


2 Answers

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
like image 169
CodingMarco Avatar answered Apr 28 '26 04:04

CodingMarco


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.

like image 32
sibaz Avatar answered Apr 28 '26 02:04

sibaz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!