git 无法合并原点/主:错误:您对以下文件的本地更改将被合并覆盖

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

Couldn't merge origin/master: error: Your local changes to the following files would be overwritten by merge

gitandroid-studiogithubmerge

提问by humazed

I make some changes and commits to my project locally but didn't push them, then I change files in GitHub by adding new file and commit.

我在本地对我的项目进行了一些更改和提交,但没有推送它们,然后我通过添加新文件并提交来更改 GitHub 中的文件。

when I try to push my local commits android studio suggested to merge but when I try to merge it give me that error and whatever I do keep refusing to merge and show me that message.

当我尝试推送我的本地提交时,android studio 建议合并,但是当我尝试合并时,它给了我那个错误,无论我做什么,都拒绝合并并向我显示该消息。

enter image description here

在此处输入图片说明

and when I click merge shows me.

当我点击合并显示我。

Error message:

错误信息:

enter image description here

在此处输入图片说明

My log:

我的日志:

enter image description here

在此处输入图片说明

What should I do?

我该怎么办?

回答by seanlinsley

Your local changes will need to be stashed away while you perform the merge. To do that, git provides git stashto save your uncommitted changes to a temporary location, and git stash popto apply them back to your local code.

当您执行合并时,您的本地更改将需要隐藏起来。为此,git 提供git stash将您未提交的更改保存到临时位置,并将git stash pop它们应用回您的本地代码。

This should work:

这应该有效:

git stash
git pull origin master
git stash pop

Here's a good website to learn more about git: http://gitready.com/beginner/2009/03/13/smartly-save-stashes.html

这是一个了解 git 的好网站:http: //gitready.com/beginner/2009/03/13/smartly-save-stashes.html

But after looking at your screenshot, a merge doesn't seem like the best option for you. Instead a rebase would make more sense.

但是在查看您的屏幕截图后,合并似乎不是您的最佳选择。相反,变基会更有意义。

git stash
git pull --rebase origin master
git stash pop

Here are some resources to understand the difference between a merge and a rebase:

这里有一些资源可以理解合并和变基之间的区别:

回答by APJ

First: you have to pull to merge your old code with the new one , if git can t do that automatically it will show you with lines like this --------------- in your code where you have to fix or merge manually. Follow this

第一:你必须拉取你的旧代码与新代码合并,如果git不能自动做到这一点,它会在你的代码中显示这样的行 ---------------您必须手动修复或合并。按照这个

$git pull origin master
(Fix the code if you have to)
$git add --a
$git status (you will see what is going    to change in branch)
   $git commit -m "message"

$git push origin master

$git push origin master