(I assume your hosted website has some sort of auto-deploy script. Unless you show this script, we must make some assumptions about it. For now I will assume it consists mostly or solely of a git checkout
command.)
Edit: the actual deployment code appears to be a custom OpenShift Ruby script (which is never shown on this linked page): https://developers.openshift.com/en/managing-deployments.html. Someone familiar with OpenShift and Ruby can perhaps comment on what the default deployment script really does. If it's not just git checkout
(and clearly it's not), some of the assumptions below are unlikely to hold.
Edit 2: this appears, in the end, to be a question about OpenShift. The problem appears to have nothing at all to do with git.
You can't really get around this in git, at least not without custom hacking. The reason why is simple enough:
As far as git knows, you are (on the hosted web site) asking it to move from $old_commit
(whatever ID that is) to $new_commit
(another ID).
So, git compares what's in $old_commit
vs what's in $new_commit
.
The old commit had files users/usr1/foo
and users/usr2/bar
. The new commit does not.
Therefore, git must remove those files so that it makes the correct transition from old to new.
Git will do this every time you move from $old_commit
to $new_commit
, because those are the instructions needed to convert a work tree from $prev_commit
to $new_commit
. It doesn't matter that in $new_commit
, the files are in .gitignore
(which doesn't mean "ignore", really): what matters is that they are in $old_commit
and not in $new_commit
.
But, we can observe one other thing: with any luck, git will only ever do this transition from $old_commit
to $new_commit
once. What we need to do, then, is, on the hosted web site:
- Move all the precious user files out of the way, so that they don't exist under their original names for a while;
- Cause git to do the old-to-new conversion (which should silently "remove" the now-non-existent paths); and
- Move the precious user files back.
The drawback here is that if you ever do somehow go back to $old_commit
on the hosted web site—or indeed, any old commit that has those files—and then transition it to $new_commit
(or any newer commit that no longer has the files), git will remove the files again.
It might be nice if git had an ignore syntax and/or file that marked particular files as "precious, do not destroy, though do not source control either"; but it doesn't (at least, not today).