Is there a way to assume ownership of long buried changes that were squashed onto the main branch, instead of merged?
In the picture, green branch from Green and Orange authors was squashed onto main by Blue author, resulting in obfuscated ownersip.
We have a main branch (blue) which is controlled only by the repo owner (blue dots). Green and Orange authors create feature branches that are then added to the main, however, former practice was to squash everything to "make the main clean". We have since abandoned this and do normal merges, rebases or fast-forwards, however, there are still many changes in the repo with the (incorrect) Blue author causing difficulties in communication and misunderstandings when working with the old code.
Unfortunately this has happened weeks ago and many features were already added since.
The main branch is locked, but I guess I could make the required changes on an ad-hoc branch and then try to convince the owner to rewrite the history ¯\(ツ)/¯, but a non-invasive approach that only involves merges, resets, etc. would be preferable.
I tried some combo of reverts, resets and cherry-picks on top of main, which helped me fix the ownership of those particular changes, but I am unable to re-introduce the main back on top of this branch, because an attempt to merge from main gives "already up to date", which makes sense since main was a base for this.
What can I do?
CodePudding user response:
One technical way to rewrite your history :
- run :
git replace --graft <squash merge commit> <parent1> <parent2>
This will make your local clone behave as if there was an actual merge commit instead of the squash merge.
- run :
git filter-repo --force
To make the replacements permanent.
If you can afford to rewrite the repo's history, you may try to have the maintainer update it.
Another possibility it to :
- create locally a branch with squash merges replaced with actual merges eg :
master-with-merges
) - push this branch on the remote so that everyone can access it
- add a script which runs the correct
git replace
command so that everyone can have a local view of the "actual" merges