git pull origin master给出合并冲突:我该怎么办?

时间:2014-01-03 17:47:20

标签: git github

我正在处理我从master创建的分支(my-branch)。

$ git checkout -b my-branch

我编辑了一些文件,然后将它们检入新分支:

$ git commit -a -m 'Add new feature'

然后我从主人那里撤出(我不完全确定我为什么这样做,或者这是不错的做法):

$ git pull origin master 

但拉动给了我很多错误信息:

   From github.com
 * branch            master     -> FETCH_HEAD
Auto-merging styles/common/module_more_info.scss
CONFLICT (add/add): Merge conflict in styles/common/module_more_info.scss
Auto-merging app/support/stagecraft_stub/responses/cloud.json
CONFLICT (content): Merge conflict in app/support/stagecraft_stub/responses/cloud.json
Auto-merging app/support/backdrop_stub/response_fetcher.js
CONFLICT (content): Merge conflict in app/support/backdrop_stub/response_fetcher.js
Automatic merge failed; fix conflicts and then commit the result.
vagrant@pp-development-1:/var/apps/spotlight$ git status

现在运行git status会显示许多已更改的文件:

#On branch my-branch

# Changes to be committed:
#
#       modified:   CONTRIBUTING.md
#       modified:   README.md
#       modified:   app/appBuilder.js
[lots more files]
#
# Unmerged paths:
#   (use "git add/rm <file>..." as appropriate to mark resolution)
#
#       both modified:      app/support/backdrop_stub/response_fetcher.js
#       both modified:      app/support/stagecraft_stub/responses/cloud.json
#       both added:         styles/common/module_more_info.scss

首先,发生了什么,其次,我该怎么做?

如果我试图查看上面任何文件列表中的差异,我会得到空输出,这是令人困惑的(如果没有差异,为什么它要我提交文件?):

$ git diff CONTRIBUTING.md
$

我应该查看Unmerged paths下的三个文件,然后将其作为合并提交提交吗?更新:最重要的是,我可以将它推送到我的分支而不会弄乱主分支吗?

我似乎无法回滚最后一次提交。

5 个答案:

答案 0 :(得分:3)

不要使用合并工具,因为它让您感到困惑。请备份当前代码并还原当前分支中的更改。然后检查你的主人(dev),得到最新的然后重写你的更改,然后推。

首先,你需要在你的github中输入gitk --all哪个分支目前将通过显示的顶部打开

然后您需要使用服务器最新代码revertrebase您的代码:

然后

检查输入以下内容以将分支推送到服务器主服务器。

git status

git add .

git status

git commit -a -m "Comments"

git push origin yourbranchname

这就是......

答案 1 :(得分:0)

基本上,是的。 git mergetool可能会有所帮助。它只是打开一个合并工具,其中包含需要您注意的文件,然后将它们添加到索引中。使用简单的git commit,您可以创建合并冲突。

执行git reset --hard HEAD时,您可以随时返回到拉动前的状态。

答案 2 :(得分:0)

可能发生的是:

  1. 其他人正在编辑或合并它与Master的代码。
  2. 您与编辑Master的最后一位用户拥有不同的字符集。
  3. 解决方案是:

    git mergetool <you can left here blank your choose a mergetool from those you have installed in your machine>
    

答案 3 :(得分:0)

首先配置您的合并工具。我建议安装this

  • 现在您的更改与远程更改冲突,您必须解决冲突。 对每个文件都这样做:

    • git merge tool

    • 保存文件。

现在你说git你知道存在冲突,但你想用你使用合并工具的方式解决它们。所以冲突现在已经解决了。

git status

现在你必须提交已解析的文件然后推送它们。

PS。另一种方法是隐藏你的更改而不是提交然后从原点拉出然后弹出你的stas。

git stash save
git pull
git stash pop
git commit
git pull

但是,如果您确定要进行更改,我必须按照您的方式提交它们然后合并它们。经常合并,你必须知道如何处理它。

答案 4 :(得分:-1)

打开冲突文件并解决删除差异的问题。

然后:

git add . 
git commit -am "resolve conflicts"
git push origin master
相关问题