Super-engineer Raymond Chen is back with another installment of his git wisdom series:
- How do I split a file into two while preserving git line history?
This time, the octopus merge succeeds.[...] there are no merge conflicts. [...] And lo and behold, all three resulting files preserved the original line histories.
- How to split out pieces of a file while preserving git line history: The hard way with commit-tree
A related scenario is where you want to extract some pieces of a file into separate files, but leave some pieces behind.
- How to split out pieces of a file while preserving git line history: The easy way with misleading commits
Last time, we split pieces of a file into separate files while preserving line history. We had to do some git commit-tree magic to get the results we wanted. But there’s a way to do this with an octopus merge. You just have to make sure to keep the octopus happy.
- How to duplicate a file while preserving git line history
This could be useful if you want two copies of a component, say, one where you are doing a bunch of disruptive work, and another that remains largely unchanged. The project continues to use the old, stable version, but there’s a feature flag to switch to the new, exciting one. Eventually, you’ll make the new, exciting one the default version.
When you do this, you want the line history of the new version to be the same as the line history of the old version, because the new version is basically a fork of the old version.
- Why perform all these complex git machinations when you can just tweak the command line to get what you want?
By fiddling with command line options, say by using -C20% or -C -C -C, we can get git blame to produce the desired results.
But that’s not practical for various reasons.
- Stop cherry-picking, start merging, Part 11: Chasing the commit by taking a train
Commit the merge into your feature branch and wait for the next train from your feature branch to the victim branch. Keep watching the train schedules until your merge commit finally catches up to the original commit. Once that’s done, you can commit the other merge into the final destination branch.
Have fun, and remember, whatever you do: "You just have to make sure to keep the octopus happy."