Git 合并错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6006737/
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
Git merge errors
提问by Sayanee
I have a git branch called 9-sign-in-out
with perfectly working code, and I want to turn it into the master. I'm currently on the master branch.
我有一个9-sign-in-out
使用完美工作代码调用的 git 分支,我想把它变成主分支。我目前在主分支上。
$ git branch
9-sign-in-out
* master
I'm trying to switch to 9-sign-in-out
branch, but it doesn't allow me to:
我正在尝试切换到9-sign-in-out
分支,但它不允许我:
$ git checkout 9-sign-in-out
app/helpers/application_helper.rb: needs merge
config/routes.rb: needs merge
error: you need to resolve your current index first
Any idea how can I ignore all the master branch errors and turn the 9-sign-in-out
branch into the master? Maybe git rebase? But I don't want to lose the code in 9-sign-in-out
branch.
知道如何忽略所有主分支错误并将9-sign-in-out
分支变成主分支吗?也许 git rebase?但我不想丢失9-sign-in-out
分支中的代码。
回答by Mark Longair
It's worth understanding what those error messages mean - needs merge
and error: you need to resolve your current index first
indicate that a merge failed, and that there are conflicts in those files. If you've decided that whatever merge you were trying to do was a bad idea after all, you can put things back to normal with:
值得了解这些错误消息的含义 -needs merge
并error: you need to resolve your current index first
表明合并失败,以及这些文件中存在冲突。如果您已经决定无论您尝试进行什么合并都是一个坏主意,您可以通过以下方式将事情恢复正常:
git reset --merge
However, otherwise you should resolve those merge conflicts, as described in the git manual.
但是,否则您应该解决这些合并冲突,如 git 手册中所述。
Once you've dealt with that by either technique you should be able to checkout the 9-sign-in-out
branch. The problem with just renaming your 9-sign-in-out
to master
, as suggested in wRAR's answeris that if you've shared your previous master branch with anyone, this will create problems for them, since if the history of the two branches diverged, you'll be publishing rewritten history.
一旦你通过任何一种技术处理了这个问题,你应该能够结帐9-sign-in-out
分支。只需重命名的问题你9-sign-in-out
来master
,如建议WRAR的回答是,如果你共享你以前的主分支与任何人,这会产生问题对他们来说,因为如果两个分支的历史分歧,你会被改写出版历史。
Essentially what you want to do is to merge your topic branch 9-sign-in-out
into master
but exactly keep the versions of the files in the topic branch. You could do this with the following steps:
本质上,您想要做的是将主题分支合并9-sign-in-out
到主题分支中,master
但准确地保留主题分支中的文件版本。您可以通过以下步骤执行此操作:
# Switch to the topic branch:
git checkout 9-sign-in-out
# Create a merge commit, which looks as if it's merging in from master, but is
# actually discarding everything from the master branch and keeping everything
# from 9-sign-in-out:
git merge -s ours master
# Switch back to the master branch:
git checkout master
# Merge the topic branch into master - this should now be a fast-forward
# that leaves you with master exactly as 9-sign-in-out was:
git merge 9-sign-in-out
回答by wRAR
git checkout -f 9-sign-in-out # change branch, discarding all local modifications
git branch -M master # rename the current branch to master, discarding current master
回答by Jingpeng Wu
as suggested in git status
,
正如建议的那样git status
,
Unmerged paths:
(use "git add <file>..." to mark resolution)
both modified: a.jl
both modified: b.jl
I used git add
to finish the merging, then git checkout
works fine.
我曾经git add
完成合并,然后git checkout
工作正常。
回答by Muhammad Shoaib Murtaza
my issue was (master|REBASE 1/1)
我的问题是 (master|REBASE 1/1)
this command worked for me
这个命令对我有用
git rebase --skip
回答by Parasp2008
git commit -m "Merged master fixed conflict."
git commit -m "合并的主修复冲突。"