1

I've forked project where I rewrote 90% of huge Makefile. After reviewing my pull request, upstream maintainer proposed me to put all my changes in a new makefile beside of original to have a transition period.

Since I worked on main Makefile it now has tens of my commits and now I should jump to a branching point, make a copy of original file as Makefile.new and somehow apply all my commits on top of this new file to retain a history of my changes. Then I should revert all my changes from original Makefile to retain its own history.

This isn't a case for rebasing, so I'm not sure how it can be achieved without handpicking all my commits.

Oleksandr
  • 419
  • 3
  • 14

1 Answers1

1

Why not just keep your branch history as is, and then add two new commits:

mv Makefile MAkefile.new
git add .
git commit
git checkout master -- Makefile
git commit

This will preserve your history, revert Makefile to its original state, and put your changed version under the new name.

The reason to do it in 2 commits is so that rename detection can "follow' what happened, making it easier to see the history of MAkefile.new specifically. If this isn't a concern - if your team typically looks at full patches to understand history - then you could do it in a single commit just as well.

Mark Adelsberger
  • 42,148
  • 4
  • 35
  • 52
  • This is good and straightforward solution, I'll consider it if no other will be proposed. There only one downside for me: original `Makefile` will share all commit history of `Makefile.new` which was a `Makefile` before `git mv` point. My target is completely separate commit histories for both files. – Oleksandr Feb 12 '19 at 15:44
  • 1
    @stunpix - The ship for "completely separate commit histories' sailed when you started making commits that introduced your changes at the existing file's path. To get that now, you would need a history rewrite - which in a shared repo, has some rather exterme costs. If you want to understand what's involved in that, the command you'd use is `git filter-branch`. – Mark Adelsberger Feb 12 '19 at 15:49
  • Thank you for pointing me on `git filter-branch`. It done for me absolutely all what I needed. – Oleksandr Feb 13 '19 at 12:47
  • This is what I've done: `git filter-branch --tree-filter 'cp Makefile Makefile.new && git checkout master -- Makefile' HEAD~31..HEAD` – Oleksandr Feb 13 '19 at 12:54