In our project we have a model comparator that checks the performance of the code and saves the statistics together with the git hash of the commit. The problem is that in many cases this commit becomes orphaned later, and we cannot retrieve the commit just using the git hash.
I've proposed a solution to merge the commit on a special shelter
branch right after saving the statistics. That would allow us to have a single branch that is responsible for keeping the commits alive (this branch can even be made restricted to prevent losing the commits after the merge). This solution however opens another problem with possible merge conflicts that are undesirable while automatic merge from script; my final idea is to use the ours
strategy for merging: git merge -s ours <hash>
. This merge strategy doesn't take a single line from the commit we are merging, and just makes a dummy commit that belongs to the shelter
while being a dependent of the commit that otherwise may become orphaned.
To convince the team that this strategy would work I need to provide a written evidence from the git reference that clearly states that even the -s ours
strategy preserves the commit from garbage collecting (the fact that this strategy doesn't take a single line from the source commit introduces some uncertainty). So far I've found a vague statement:
git gc tries very hard not to delete objects that are referenced anywhere in your repository. In particular, it will keep not only objects referenced by your current set of branches and tags, but also objects referenced by the index, remote-tracking branches, notes saved by git notes under refs/notes/, reflogs (which may reference commits in branches that were later amended or rewound), and anything else in the refs/* namespace. If you are expecting some objects to be deleted and they aren’t, check all of those locations and decide whether it makes sense in your case to remove those references.
This quote doesn't say anything about different merge strategies, and I expect a devil in the detail. For example, git merge --squash
, being a "merge", doesn't preserve the dependencies.
My question is whether there is an explicit statement that resolves the ambiguity for the git merge -s ours
strategy.