你如何 git fetch 然后合并?“错误:您对以下文件的本地更改将被合并覆盖”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9588111/
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-10 13:08:02  来源:igfitidea点击:

How do you git fetch then merge? "Error: Your local changes to the following files would be overwritten by merge"

gitgit-mergegit-fetch

提问by ario

Newbie Git question: I have a repo set up on bitbucket. I git fetched someone else's changes and would like to merge them with my own. However, when I try to git merge (or git merge origin/master), I get the message "error: Your local changes to the following files would be overwritten by merge:", and then a list of files I've changed. Having Git merge these changes is exactly what I want to do though.

新手 Git 问题:我在 bitbucket 上设置了一个存储库。我 git 获取了其他人的更改,并希望将它们与我自己的合并。但是,当我尝试 git merge(或 git merge origin/master)时,我收到消息“错误:您对以下文件的本地更改将被合并覆盖:”,然后是我已更改的文件列表。让 Git 合并这些更改正是我想要做的。

回答by ralphtheninja

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

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

git stash
git merge origin/master
git stash pop

回答by mamills

If you want to keep your changes, you can commit your changes to your local repository first and then merge the remote repository.

如果要保留更改,可以先将更改提交到本地存储库,然后合并远程存储库。