我已经阅读了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.
我该怎么做才能回到我的主分支?
我想要明确的第一件事是,分支名称只是特定提交的别名。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.
当你使用命令git merge brancha branchb合并两个分支时,有两种可能:
通过跟踪一个分支(我们称之为brancha)的提交历史,另一个分支(我们称之为branchb)可以到达它。在这种情况下,git只需快进头指向最近的分支(在这种情况下是branchb)。
2.但是如果两个分支在某个较旧的点上分离了,那么git会创建一个新的快照并添加一个指向它的新提交。所以如果
合并的分支之间没有冲突,git平滑地创建了一个新的提交。
运行git log查看合并两个不冲突分支后的提交情况。
现在回到有趣的情况,合并分支之间存在合并冲突。这句话摘自https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging页
Git没有自动创建新的合并提交。在您解决冲突时,它暂停了进程。如果你想在合并冲突发生后的任何时刻查看哪些文件未合并,你可以运行git status
因此,如果存在合并冲突,你需要解决冲突,然后使用git add filename将你所做的更改添加到暂存区域,然后使用git commit命令提交这些更改,git会因为冲突暂停该命令。我希望这能解释你的问题。也请访问上面的链接以获得详细的了解。如果有任何疑问,请在下面评论,我很乐意帮助。
我如何完成合并后解决我的合并冲突?
使用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.