-1

I have a branch of local project changes based on a foreign upstream branch. The branch has got increasingly hard to maintain as the changes age and the upstream branch changes. In particular all of the upstream files were reformatted (whitespace) recently. Rebases end up with a lot of conflicts that I continually have to reapply. Since I know the changes are good what I would like to do is generate a clean set of HEAD commits that is then easy to rebase. I am considering doing this by generating a patch between upstream and my branch and then applying the patch to a branch of upstream and then finally committing all the changes on a subsystem basis. Obviously a bit of manual work, my question is - is there an easier way to do this?

Not tried anything yet other than git pull --rebase upstream upstream-branch continually creates conflicts

It's open source so I can point you directly at the code! https://github.com/ArduPilot/ChibiOS.svn/pull/1

https://github.com/ArduPilot/ChibiOS.svn/tree/stable_21.11.x is a git mirror of the stable branch of a svn repository. The pull request is all the changes which are also mixed in with fixes to the formatting

Andy Piper
  • 563
  • 4
  • 10
  • You're looking for [`git rerere`](https://git-scm.com/docs/git-rerere), built for exactly this. – jthill Feb 01 '23 at 16:03
  • The easier way is likely to merge, not rebase - are your changes in active development or static? How many commits are in this branch? why not just squash them together so there's only one commit to deal with? please edit the question to add some more details about the situation you're asking about. – AD7six Feb 01 '23 at 16:05
  • git rerere requires that I go through all the painful rebases again just so that I can avoid them in the future. I don't want to go through any more. It also won't work for other people trying to do thuis – Andy Piper Feb 01 '23 at 17:39
  • Git doesn't really care what you want. If you don't want to continually reapply the fixes for the same conflicts over and over, you will enact the rebase one more time with `git rerere` watching you. That's how it works. – matt Feb 01 '23 at 17:54
  • [You can light it retroactively](https://stackoverflow.com/questions/59167367/can-git-rerere-be-applied-retroactively). – jthill Feb 01 '23 at 20:14

1 Answers1

0

Clearly my question was not clear enough, but answers along the lines of "that's how git works" was not what I was looking for. I solved this with my original suggestion. Which was something along the lines of:

git checkout upstream-branch
git checkout -b clean-branch
git checkout dirty-branch
git format-patch clean-branch
cat *.patch > mega.patch
git checkout clean-branch
patch -p1 < mega.patch
<individually commit each subsystem>
git push -set-upstream upstream-branch clean-branch

I now have a clean set of commits that rebase cleanly against upstream-branch without the need for rerere

Andy Piper
  • 563
  • 4
  • 10