问题
I've been working with another developer across three servers:
- My local VM
- Dev server
- Live server
The workflow that I adopted was to, obiously, do all the work on my local VM, then pull the changes form the repomote repository to the dev server (dev branch) and live server (master beanch after merging with dev branch).
Unfortunately, another developer modified some files, install Wordpress plugins directly on the live server. Consequently, when I attempt to bring the master branch on the live server up to date with master on the remote reposiotry, I get messages like this one:
Error: Your local changes to 'plugins/bulk-page-creator/bulk-page-creator.php' would be overwritten by merge. Aborting.
Please, commit your changes or stash them before you can merge.
I guess that these files are not tracked. I really want to avoid commiting to the remote repo from a server other than my local VM.
What are my opitons here to resolve this problem. I just need to bring the codebase on the live server up to date with the remote repo - that's it.
Should I somehow discard these local changes?
I also attempted to synchronize the codebase with:
git fetch
git merge FEATCH_HEAD
with no luck.
What are my options here?
回答1:
You are right, you get that message because the files already exist locally, are not tracked in the currently checked out version, and the commit you are trying to merge in contains the file.
When Git already knows the file before the merge, then it can safely agree to overwrite it, but in this situation there is the chance that you have the file and don’t know that Git would now overwrite it, so Git simply won’t do it.
To resolve this issue, you just need to make room for Git to perform the merge. You can do this in two simple ways:
- Delete the file. That way, Git will be able to check out the file from the new commit without any conflicts.
- Rename the file. Same as above, but you have the chance to recover your local changes in case you want to make sure that everything you did locally is also included in the tracked file.
来源:https://stackoverflow.com/questions/30351525/git-workflow-your-local-changes-would-be-overwritten-by-merge