Git合并错误 [英] Git merge errors

查看:1121
本文介绍了Git合并错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 9-sign-in-out 的git分支,它具有完美的工作代码,我想将它转换为master。

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.

$ git branch
9-sign-in-out
* master

我试图切换到 9登录-out 分支,但它不允许我:

I'm trying to switch to 9-sign-in-out branch, but it doesn't allow me to:

$ 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

如何忽略所有主分支错误并将 9注销分支到主?也许git 重建?但我不想失去 9-sign-in-out 分支中的代码。

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.

推荐答案

值得了解这些错误消息的含义 - 需要合并错误:您需要先解析当前索引表示合并失败,并且这些文件中存在冲突。如果你已经决定,无论你想要做什么合并是一个坏主意,你可以用以下方法恢复正常:

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:

git reset --merge

但是,否则您应该解决这些合并冲突,如git手册中所述

However, otherwise you should resolve those merge conflicts, as described in the git manual.

通过这两种方法处理完毕后,您应该可以检出 9注销分支。正如 9-sign-in-out 重命名为 master https://stackoverflow.com/questions/6006737/git-merge-errors/6006775#6006775\"> wRAR的答案是,如果你已经与任何人分享你以前的主分支,这会给他们带来问题,因为如果两个分支的历史发生了分歧,那么您将发布重写的历史记录。

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 answer is 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-out-out 转换为 master ,但确切地保留主题分支中的文件版本。您可以通过以下步骤完成此操作:

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:

# 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

这篇关于Git合并错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆