I needed to optimize the history of my first repository (a fork of another rep), which (of course) was very buggy. Over 3 years a lot of garbage had accumulated there; there was data that shouldn’t be there and hundreds of extra commits that made it hard to navigate through the rep’s history.
Normally, you could squash everything right “hot”. However, because of the multitude of merges, it is no longer squeezable.
The first thing I tried was to clone upstream-master into a new branch. I started to cherry-pick commits there from my origin-master (see screenshot on the left). But then I got in trouble. My main fork-origin was intertwined with upstream. As a result, I had to scratch out chunks of commits. In general, it was a total mess: 2019 on the bottom, 2020+ on the top (see screenshot below).
How to solve this issue:
make empty branch:
git checkout --orphan BRANCH_NAME
Clean it up:
git rm -rf .
Now you can use your hands to take the cherries and put them in the right order on the cake 😉 But…
If you work in GUI client of the git – empty repo will disappear if you don’t post anything in it. So either you need to `push` some readme yourself there or make it nice and cherry-pick the first commit from the git-bash right away. To do this, we first get the source:
git remote add other https://example.link/repository.git
git fetch other
Now make first cherry-pick, for example:
$ git cherry-pick 7426dcff775e43fc71ea42b7cb146e5551c44804
Alrighty, we can untie remote and go back to GUI:
git remote remove other
Hope to see your feedback in comments!