1

The situation:

1) I forked an 'original' repo, and started working on the 'forked' repo with other people

2) FastForward ~250 commits, and I change my github username, and also obtain a new no-reply email

3) I rebase all history to replace my name and email in each commit I'd made (believing I was only affecting my commits)

4) Force push into the remote forked repo, all the other teammates clone it from scratch and we keep moving

Problem:

When attempting to submit a pull request to the original repo (step 1) I realize my rebase deleted all signatures that were made in the commits we cloned from the original repo. This caused almost the entire history to change, due to signatures being part of the commit hash. Now I'm 500 commits ahead and ~250 behind original/master

Desired result:

desired git history

What I want to achieve:

I want to grab the entire history of our work in 'forked' (commits after ~250) and rebase it on top of 'original' (this time, without altering their commits) so it can be merged into 'original'

In the final version, I would like to keep the history as is. All commits authored by who authored it, no squashing merge commits, and the likes. Is there any way to achieve that?

Tried:

1) merge --allow-unrrelated-histories

git clone original-url
git remote add new-repo forked-url
git checkout -b new forked/master
git checkout master
git merge new --allow-unrrelated-histories

=> Leads to a working solution, but duplicates almost all original commits (without signatures) which I would like to avoid.

2) rebase

git clone original-url
git remote add new-repo forked-url
git checkout -b new forked/master
git rebase -i master

=> Leads to working solution, but the entire 'forked' history is ripped apart and replaced with a single line of commits (all merges are lost, all different tracks are lost). For instance, almost all my teammates collaborations are lost, as git interprets every commit as made by me. They don't even figure as contributors.

1 Answers1

1

Leads to working solution, but the entire 'forked' history is ripped apart and replaced with a single line of commits (all merges are lost, all different tracks are lost).

That is because you have done a simple rebase.

Try, preferably with the most recent Git version possible, a git rebase --rebase-merges

git rebase --rebase-merges master

That will transplant the whole topology of commit graph.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks! That solved the problem. I'm on ubuntu 18.04 with git 2.17 installed (you get that by default) and that command wasn't available. I added git's ppa and upgraded git to 2.22 ```sudo add-apt-repository ppa:git-core/ppa ; sudo apt update; sudo apt upgrade``` and I was able to do it – nahuelarjonadev Aug 16 '19 at 20:42
  • 1
    @NahuelArjona Well done. As my link indicated (https://stackoverflow.com/a/50555740/6309), `git rebase --rebase-merges` was introduced in Git 2.18. But even Git 2.22 was still improving it. – VonC Aug 16 '19 at 20:44