我已经阅读了Git社区手册的基本分支和合并部分。
所以我遵循它,创建了一个分支:实验。
然后我:
切换到实验分支(git校验实验)
做一些改变
提交(git Commit -a)
切换到主分支(git checkout master)
做一些修改并提交
切换回实验性(git checkout experimental)
合并主机更改为实验性(git合并主机)
有一些冲突,但在我解决后,我做了'git add myfile'
现在我被困住了,我不能回到主人那里
当我做的时候
$ git checkout master
error: Entry 'res/layout/my_item.xml' would be overwritten by merge. Cannot merge.
我照做了:
$ git rebase --abort
没有正在进行的调整?
我照做了:
$ git add res/layout/socialhub_list_item.xml
$ git checkout master
error: Entry 'res/layout/my_item.xml' would be overwritten by merge. Cannot merge.
我该怎么做才能回到我的主分支?
我如何完成合并后解决我的合并冲突?
使用Git 2.12(2017年第一季度),您将拥有更自然的命令:
git merge --continue
如果你不想在继续/恢复合并时编辑消息:
git merge --continue --no-edit
如果——no-edit不起作用,正如akseli在评论中报告的那样,你可以这样做:
# Linux
GIT_EDITOR=true git merge --continue
# Windows
cmd /V /C "set "GIT_EDITOR=true" && git merge --continue"
您可以为这些命令定义别名。
参见Jeff King (peff)提交c7d227d(2016年12月15日)。
参见Chris Packham (cpackham)的commit 042e290, commit c261a87, commit 367ff69(2016年12月14日)。
(由Junio C Hamano合并- gitster -在提交05f6e1b, 2016年12月27日)
参见2.12版本说明。
合并:添加“——continue”选项作为“git commit”的同义词
教会'git merge'——continue选项,允许' continue ' a
通过完成合并。
解决冲突后完成合并的传统方法是使用'git commit'。
现在像'git rebase'和'git cherry-pick'这样的命令有一个'——continue'选项,添加这样一个选项到'git merge'会呈现一个一致的UI。
我想要明确的第一件事是,分支名称只是特定提交的别名。commit是git的工作,当你拖拽merge等等。每个提交都有一个唯一的id。
当你做$ git合并时,实际发生的事情是git试图快进你的当前分支到被引用的分支所在的提交(换句话说,两个分支名称都指向同一个提交)。这个场景对于git来说是最容易处理的,因为没有新的提交。想象一下主人跳上你的树枝上的百合花。可以设置——no-ff标志,在这种情况下,无论是否有任何代码冲突,git都会创建一个新的提交。
In a situation where there are code conflicts between the two branches you are trying to merge (usually two branches whose commit history share a common commit in the past), the fast forward won't work. git may still be able to automatically merge the files, so long as the same line wasn't changed by both branches in a conflicting file. in this case, git will merge the conflicting files for you AND automatically commit them. You can preview how git did by doing $ git diff --cached. Or you can pass the --no-commit flag to the merge command, which will leave modified files in your index you'll need to add and commit. But you can $ git diff these files to review what the merge will change.
The third scenario is when there are conflicts git can't automatically resolve. In this case you'll need to manually merge them. In my opinion this is easiest to do with a merge took, like araxis merge or p4merge (free). Either way, you have to do each file one by one. If the merge ever seems to be stuck, use $ git merge --continue, to nudge it along. Git should tell you if it can't continue, and if so why not. If you feel you loused up the merge at some point, you can do $ git merge --abort, and any merging will undo and you can start over. When you're done, each file you merged will be a modified file that needs to be added and committed. You can verify where the files are with $ git status. If you haven't committed the merged files yet. You need to do that to complete the merge. You have to complete the merge or abort the merge before you can switch branches.