git-mit icon indicating copy to clipboard operation
git-mit copied to clipboard

Don't modify commits on rebase

Open mattwynne opened this issue 1 year ago • 6 comments

Is your feature request related to a problem? Please describe. I've noticed that if I'm working in a branch and I rebase from main, all the commits in the branch end up with the current set of configured co-authors on them. So the original co-author info in the branch is lost.

Describe the solution you'd like When doing a rebase, don't modify the co-author trailer on the rebased commits.

Describe alternatives you've considered Live with it? :)

mattwynne avatar Jul 19 '24 17:07 mattwynne

ooh that's a tricky one, seems annoying though. I will have a look (also open to PRs if you feel comfortable with that)

PurpleBooth avatar Jul 20 '24 09:07 PurpleBooth

What would you expect, the rebaser to be represented in the trailers, but added to the existing ones, to appear as "the committer" or just make no change?

PurpleBooth avatar Jul 20 '24 10:07 PurpleBooth

My instinct would be just to leave the commits as-is in the scenario I’m talking about.

I guess there are cases where you’re doing an interactive rebase and you might want something else, but I’d say those are more niche and people can manually add commit trailers if they want to in those situations.

mattwynne avatar Jul 22 '24 13:07 mattwynne

This is the behaviour I am going to add, seem sensible? I'll do it as opt in then push a change to make it the default with a major bump

Rebases

It might be preferable not to do this on rebase, you can disable this happening on rebase by running

git mit-config mit rebase-behaviour no-change

lets say we have two diverging branches

echo "Lorem Ipsum" >> new-so-no-conflicts.md
git switch -c rebase-demo-branch
git switch -
git commit --all --message="Diverging commit" --quiet
git switch -

Now you can rebase changes without adding any additional trailers

git mit bt se
echo "Lorem Ipsum" >> README.md

git commit --all --message="Rebase behaviour
" --quiet
git show --pretty='format:author: [%an %ae] signed-by: [%GS] 
---
%B' -q
author: [Billie Thompson [email protected]] signed-by: [] 
---
Rebase behaviour

Co-authored-by: Someone Else <[email protected]>

Then if you rebase the commit stays the same

git mit bt ae
git rebase --reset-author-date "-"
ls .git
echo ----
cat .git/AUTO_MERGE
echo ----
cat .git/HEAD
echo ----
cat .git/ORIG_HEAD
echo ----
git show --pretty='format:author: [%an %ae] signed-by: [%GS] 
---
%B' -q
author: [Billie Thompson [email protected]] signed-by: [] 
---
Rebase behaviour

Co-authored-by: Someone Else <[email protected]>

The default setting is to modify the co-authored by.

git mit-config mit rebase-behaviour add-to

Now you can rebase changes without adding any additional trailers

git mit bt se
git rebase --reset-author-date "-"
git show --pretty='format:author: [%an %ae] signed-by: [%GS] 
---
%B' -q
author: [Billie Thompson [email protected]] signed-by: [] 
---
Rebase behaviour

Co-authored-by: Someone Else <[email protected]>
Co-authored-by: Anyone Else <[email protected]>

PurpleBooth avatar Jul 23 '24 08:07 PurpleBooth

Perfect! 🙌🏻

mattwynne avatar Jul 23 '24 13:07 mattwynne

This should be out now, not defaulted yet.

git mit-config mit set-non-clean-behaviour no-change

to turn it on

PurpleBooth avatar Jul 27 '24 08:07 PurpleBooth