Git workflow: “Your local changes would be overwritten by merge”

﹥>﹥吖頭↗ 提交于 2020-01-11 12:57:30

问题


I've been working with another developer across three servers:

  1. My local VM
  2. Dev server
  3. 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:

  1. Delete the file. That way, Git will be able to check out the file from the new commit without any conflicts.
  2. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!