Suppose I have a git repos that contains original.script. At some point, I want to do something similar to original.script, so I decide to use it as a starting point for a new script modified.script:
% git branch before-cp
% cp original.script modified.script
% git add modified.script
% git commit -m "creating a copy to modify"
% vim modified.script #...
% git add modified.script
% git commit -m "made some modifications"
Now, at some point, I discover a bug in original.script. I can just patch original.script, but that doesn’t help modified.script which may retain the bug. I’d like to fix original.script back before it was copied, doing something like:
% git checkout before-cp
% vim original.script #...
% git add original.script
% git commit -m "fixing a bug in original before I start copying it"
% git checkout master
% git rebase before-cp
But this doesn’t work the way I want it to. The rebased “creating a copy to modify” commit still contains a copy of modified.script that’s identical to the unpatched version of original.script (from before-cp^).
I’m ok with my first attempt being the wrong way to do it – but is there a right way to do it? To retroactively patch a file so that future copies copy the patched version? Or am I going to have to manually patch modified.script (and any other files in the copy-subtree of original.script).
You have to manually patch
modified.script. When you copiedoriginal.scripttomodified.script, the new commit simply records the fact that you createdmodified.scriptwith a particular set of file contents. When looking at the diffstat, git will tell you that you copiedoriginal.scriptto createmodified.scriptbut it inferred that, the commit itself didn’t actually record that fact. If you retroactively modifyoriginal.scriptand try to rebase your commit that createsmodified.scripton top of that, it will re-create the exact samemodified.scriptthat you had before, and if you diffstat the commit, it will look like you copiedoriginal.scriptand then made some changes (effectively reverting your fix) before actually committing it.The only solution you have is to apply the same patch to
modified.script.