I have a project tracked in git that has a master branch that becomes the release for my code. I have some code in that branch that is causing problems because an external library that it relies on is currently broken. However, I expect that the external library will be “fixed” at some point in the future (weeks, so stash is not really what I want here) and that I will want to resurrect the problematic code.
So, the question:
How can I save code from a branch for future use? If I simply create a branch called saveme, make changes on the master branch, and then try to merge saveme back into master to get back the “saved” code, this seems to result in “already up-to-date”.
When you create the
savemebranch, your history looks like this:…. then when you work more on
master, to cope with the broken library, your history looks like this:So if you try to then merge
savemeintomaster, it says “Already up-to-date” because the complete history ofsavemeis already contained inmaster. It sounds as if what you want is to then create a commit which has exactly the same tree assaveme, but is just another commit on top ofmaster. You could do this by usinggit revertfor commitEand thenD, but if you want to do it in one go, you can do the following:(This is a trivial variation of the recipe I suggested in this answer.) Then your history will look like:
… but the tree of commit
Fwill be the same as that of commitC.