I have a repo in which I have a folder called /migrations
in .gitignore
they are database migration files.
Locally and on the Remote server they will be different, and I want to keep them different, however even while that folder is in gitignore, apparently there's still a conflicting issue
error: The following untracked working tree files would be overwritten by merge:
directory/backend/migrations/README
directory/backend/migrations/alembic.ini
directory/backend/migrations/env.py
directory/backend/migrations/script.py.mako
Please move or remove them before you merge.
Aborting
how do I solve this by keeping migrations folders on local and remote completely untracked and different, while still being able to update the repo seamlessly.
CodePudding user response:
This is not a "conflicting issue". It is just a rule that Git follows, quite rightly: your proposed merge contains files whose path is the same as paths you are ignoring locally, and Git doesn't want to overwrite them wantonly (and you don't want Git to do so).
It isn't enough to have the migrations folder ignored in your repo. It must be ignored in everyone's copy of this repo, and it must be absent in every branch. Clearly that's not the case.
Personally in this situation I would just do what the error message suggests: move the troublesome files aside so that merge can happen. Then bring them back again. For example, you could just move them out of the working folder to your desktop, do the merge, and move them back into the working folder again. Or, for a more Git-like way:
- Do a
git stash -u
that includes the untracked working tree files. - Do the merge.
- Now
git restore
those four files out of the stash and into the working tree.