Imagine I'm working on an exploratory branch on a git repo and it only has one commit. I decide that my work is not needed any time soon, and I don't want to create a branch/tag. In fact, I'd like to throw away the changes, but just in case I ever need them again, I'd like to save a patch.
For purposes of this post, imagine I only have one change that I want to archive:
* 040cc7c (HEAD, ExperimentalBranch) This is where the experiment is
* a29ceb7 (master) This is the main branch
...
My proposed archive solution is as follows:
- Create a patch of commit
040cc7c
. - Archive the patch file somewhere for longterm storage.
- Delete the
ExperimentalBranch
from the repo.
So far everything seems great, until years later when I might want to restore the patch. It will likely reference files/lines that are incompatible and not be able to be applied. To solve this, I could check out the patch's parent SHA and apply it there.
Therefore my proposed unarchive solution is as follows:
- Checkout SHA
a29ceb7
. - Apply the patch.
The only problem is that when I create the patch, I see that it contains SHA 040cc7c
, but does not mention a29ceb7
anywhere. It could be very hard for me to figure out the parent of 040cc7c
years after I created the patch. Furthermore, because I deleted the branch years earlier, I wouldn't expect there to be a git command that could help me discover the parent.
When creating a patch, is there a way to ensure that its parent SHA is included in the file as well?
My current workaround is to rename the patch to include the parent's SHA, but this can be easy to forget, and is more manual.