GIT - Rewriting core code on a separate branch -


i have scenario not think uncommon struggling find example of how done on net.

we have our project, master branch. example lets current state of master identifies v1.5.0 of project.

now decide write v2.0.0, massive changes , rewrites happen, files removed , deleted. rewrite takes place on new branch shall call unstable.

a week or development on unstable feature and/or bugfix needs added v1.5.0, no problem new branch - write feature - merge master. master @ v1.6.0.

now, fix/feature not apply new version of project the entire project being rewritten.

we complete v2.0.0 on unstable branch based on v1.5.0 of master branch @ say... v1.8.4 - how go merging unstable branch master branch without: destroying history of versions 1.5 through 1.8.4 or leaving artefacts pre 2.0.0 versions in merged branch , possibly breaking new code written in v2.0.0?

you know git merge -s ours, opposite of want do: ignores changes in source branch , lets merge result identical contents of target branch. there no corresponding -s theirs, though, reasons i'm not going go here.

so, we'll have improvise has same effect. rough outline: merge without committing, magically mangle 2.0.0 code it, , finalize merge.

first off, make sure have no uncommitted changes. we're going using fun tricks here; warranty void , that.

  1. on master, git merge -n unstable. -n make sure merge isn't committed yet, if there no conflicts (of course you'll conflicts due extensive rewriting, let's safe).
  2. this magic: git read-tree --reset -u unstable (read unstable index , update working tree accordingly, ignoring conflicts)
  3. git commit finalize merge. have both old , new in history, 2.0.0 stuff in tree.
  4. check whole thing left no remnants of previous master version untracked files. don't know sure whether can happen, can't hurt check.

Comments