我已经阅读了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.

我该怎么做才能回到我的主分支?


当前回答

解决冲突的步骤:

第一次“签出”到你想从另一个分支合并的分支 分支(BRANCH_NAME_TO_BE_MERGED)


"git checkout "MAIN_BRANCH"

然后使用命令将其与“MAIN_BRANCH”合并:

“git merge origin/BRANCH_NAME_TO_BE_MERGED”


Auto-merging src/file1.py
CONFLICT (content): Merge conflict in src/file1.py
Auto-merging src/services/docker/filexyz.py
Auto-merging src/cache.py
Auto-merging src/props.py
CONFLICT (content): Merge conflict in src/props.py
Auto-merging src/app.py
CONFLICT (content): Merge conflict in src/app.py
Auto-merging file3
CONFLICT (content): Merge conflict in file3
Automatic merge failed; fix conflicts and then commit the result.

现在你可以看到它正在显示“冲突(内容)”,对那些有“冲突”的文件,看到你的代码并解决它们

运行"git status" =>它会显示你需要添加的文件(你已经解决了):


 Unmerged paths:
      (use "git add <file>..." to mark resolution)

        both modified:   file3
        both modified:   src/app.py
        both modified:   src/props.py
        both modified:   src/utils/file1.py

解决了所有冲突后,使用下面的git命令逐个添加每个文件


git add file3
git add src/app.py
git add src/props.py
git add src/utils/file1.py

“git提交” (当你要提交的时候添加一些消息,如果没有,它会打开vi或vim编辑器,你需要按“esc:q!”然后按“enter”) 再次运行"git status"


 On branch MAIN_BRANCH
  Your branch is ahead of 'origin/MAIN_BRANCH' by 10 commits.
  (use "git push" to publish your local commits)

7.git push”

其他回答

我想要明确的第一件事是,分支名称只是特定提交的别名。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状态(这将显示继续自动合并过程需要哪些命令) [命令git建议,例如git merge—continue, git cherry-pick—continue, git rebase—continue]

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

添加完所有文件后,下一步是“git提交”。

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

交出来就行。

可选的git中止它: 我遇到了合并冲突。如何终止合并?

为了简化合并操作,安装kdiff3并将其配置为合并工具。产品说明:http://doodkin.com/2016/05/29/git-merge-easy-github-this-branch-has-conflicts-that-must-be-resolved-use-the-command-line/

该页面包含以下视频:https://www.youtube.com/watch?v=Cc4xPp7Iuzo