Git合并错误

我有一个git分支,叫做9-sign-in-out ,代码完好,我想把它变成主人。 我目前在主分支上。

 $ 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分支变成主? 也许git rebase ? 但是我不想丢失9-sign-in-out分支的代码。

值得了解这些错误消息的含义 – needs mergeerror: you need to resolve your current index first指出合并失败,并且这些文件中存在冲突。 如果你决定不pipe你想做什么合并是一个坏主意,你可以把事情恢复正常:

 git reset --merge 

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


一旦你通过这两种方法处理了这个问题,你应该可以签出9-sign-in-out分支。 正如wRAR的答案中所build议的那样 ,重命名你的9-sign-in-out 出口的问题在于,如果你已经与任何人共享你以前的主分支,这会给他们造成问题,因为如果两个分支的历史分歧,你会发布重写的历史。

基本上你想要做的就是将你的主题分支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 
 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