git 错误:您对以下文件的本地更改将被合并覆盖:

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26659305/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 10:30:40  来源:igfitidea点击:

error: Your local changes to the following files would be overwritten by merge:

gitbitbucket

提问by Mona Jalal

I am not sure how to get rid of this error. I am using "bitbucket" to privately upload my projects but I am receiving the following error even though I have deleted all the changed files. I simply want to pull the files

我不知道如何摆脱这个错误。我正在使用“bitbucket”私下上传我的项目,但即使我删除了所有更改的文件,我仍然收到以下错误。我只是想拉文件

error: Your local changes to the following files would be overwritten by merge:
    buf.cpp
    buf.h
Please, commit your changes or stash them before you can merge.
Aborting

This is the command I used:

这是我使用的命令:

git pull origin

回答by Tonio

Deleting a file is changing it. You want those two files to be "unchanged". If you want to keep any changes you've done (including deletion), you should either stash or commit. Stashing would require unstashing (git stash popor git stash apply), while committing will probably result in a conflict which you must resolve. If you just want to revert any changes (throw them away, not interested in keeping them), you can git checkout -- buf.cpp buf.hto restore them, then try the pull.

删除文件正在改变它。您希望这两个文件“保持不变”。如果您想保留您所做的任何更改(包括删除),您应该隐藏或提交。存储将需要取消存储(git stash popgit stash apply),而提交可能会导致您必须解决的冲突。如果您只想还原任何更改(将它们扔掉,不想保留它们),您可以git checkout -- buf.cpp buf.h恢复它们,然后尝试拉取。

回答by Kabir Hossain

You can either commit your changes before you do the merge, or you stash them:

您可以在合并之前提交更改,也可以将它们隐藏起来:

git stash save
git pulll
git stash pop

Then add your changes and push to master

然后添加您的更改并推送到 master

git add .
git commit -m 'your message'
git push -u origin master

It will help you working even in a team.

即使在团队中,它也会帮助您工作。

回答by kenorb

Try adding -r, e.g.:

尝试添加-r,例如:

git pull origin -r

which will rebase your changes on top of the upstream.

这将使您的更改基于上游。

See also: How do I resolve git saying "Commit your changes or stash them before you can merge"?

另请参阅:如何解决 git 说“在合并之前提交您的更改或隐藏它们”?