我已经阅读了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 HEAD没有更新。 这个推荐将解决git重置HEAD。

其他回答

当你使用命令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添加。 Git状态(这将显示继续自动合并过程需要哪些命令) [命令git建议,例如git merge—continue, git cherry-pick—continue, git rebase—continue]

可能会晚了。这是发生,因为你的git HEAD没有更新。 这个推荐将解决git重置HEAD。

我想要明确的第一件事是,分支名称只是特定提交的别名。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提交”。

“git status”会提示要做什么:尚未添加的文件被列在底部,一旦它们都完成了,它会建议在顶部提交,在那里它解释了当前分支的合并状态。