Git 合并错误
我有一个名为 9-sign-in-out
的 git 分支,其代码工作完美,我想将其变成主分支。我目前在 master 分支上。
$ git branch
9-sign-in-out
* master
我正在尝试切换到 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
知道如何忽略所有主分支错误并将 9 -sign-in-out
分支到master?也许 git rebase ?但我不想丢失 9-sign-in-out
分支中的代码。
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
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
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
值得理解这些错误消息的含义 -
需要合并
和错误:您需要首先解析当前索引
表示合并失败,并且这些文件中存在冲突。如果您确定您尝试执行的任何合并毕竟都是一个坏主意,您可以使用以下命令使事情恢复正常:但是,否则您应该解决这些合并冲突,如 git 手册中所述。
一旦您通过任一技术处理了该问题,您应该能够签出
9-sign-in-out
分支。按照 wRAR 的答案是,如果您与任何人共享了以前的主分支,这会给他们带来问题,因为如果两个分支的历史记录出现分歧,您'将出版重写的历史。本质上,您想要做的是将主题分支
9-sign-in-out
合并到master
中,但完全保留主题分支中的文件版本。您可以通过以下步骤来完成此操作:It's worth understanding what those error messages mean -
needs merge
anderror: 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:However, otherwise you should resolve those merge conflicts, as described in the git manual.
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 your9-sign-in-out
tomaster
, 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.Essentially what you want to do is to merge your topic branch
9-sign-in-out
intomaster
but exactly keep the versions of the files in the topic branch. You could do this with the following steps:更改分支,放弃所有本地修改
将当前分支重命名为 master,放弃当前 master
Change branch, discarding all local modifications
Rename the current branch to master, discarding current master
按照 git status 中的建议,
我使用 git add 完成合并,然后 git checkout 工作正常。
as suggested in
git status
,I used
git add
to finish the merging, thengit checkout
works fine.从 dev 分支切换到 master 分支时我遇到了同样的问题。我所做的就是提交更改并切换到主分支。您可能有未提交的更改。
您也可以尝试这个
git reset --merge
。这可用于解决任何冲突并恢复。I had the same issue when switching from a dev branch to master branch. What I did was commit my changes and switch to the master branch. You might have uncommitted changes.
And also you can try this
git reset --merge
as well. This can be used to resolve any conflicts and revert.我在尝试从 dev 分支切换到 master 分支时使用 GitHub Desktop 时遇到了这个问题,即使我已经解决了所有合并冲突。
在命令行上输入 git add * 后,我可以再次切换分支。
I got this when using GitHub Desktop when trying to switch from a dev branch to master, even after I had resolved all merge conflicts.
After typing
git add *
on the command line it allowed me to switch branches again.我的问题是(master | REBASE 1/1)
这个命令对我有用
my issue was (master|REBASE 1/1)
this command worked for me
这并不能回答问题中描述的确切场景。它回答了以下场景,您最终会得到相同的错误消息。在这里发帖是因为当谷歌搜索这个链接时,这个SO链接首先出现。
这通常发生在 GitHub Desktop 用户身上。
如果您在远程删除的分支上进行了本地更改,然后从主分支合并,并且已经解决了冲突,那么现在您无法将更改移动到任何其他分支,因为:
您需要首先解析当前索引
,和
needs merge
错误,只需执行以下操作:
从这里您可以执行通常的操作。
This doesn't answer the exact scenario described in the question. It answers the following scenario which you end up with the same error messages. Posting here because this SO link comes up first when Googling for this.
This usually happens for GitHub Desktop users.
If you made changes locally on a branch that's deleted in remote, then merged from master, and already resolved conflicts, and now you cannot move your changes to any other branch because of the;
you need to resolve your current index first
,and
needs merge
error,simply do below:
From here you can do the usual.
git commit -m“合并主修复冲突。”
git commit -m "Merged master fixed conflict."