44

我只想拉。我有一些更改要忽略,我的 Gemfile 和 Gemlock 文件,我很乐意覆盖它们并拉取。我试着把我的改变藏起来,这对我没有用。我该怎么办?

git pull
M   Gemfile
U   Gemfile.lock
Pull is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm <file>'
as appropriate to mark resolution, or use 'git commit -a'.
~/projects/sms/apps2/apps2_admin(apps2)$ git stash save "saved"
Gemfile.lock: needs merge
Gemfile.lock: needs merge
Gemfile.lock: unmerged (4ea16799dba7bfe1db28adecf36dee1af5195c1a)
Gemfile.lock: unmerged (e77439c9f86d1d0eda7ae0787e3e158f90959e68)
Gemfile.lock: unmerged (d690d3860db1aa8e46c1bb2f4de3e52a297b5c26)
fatal: git-write-tree: error building trees
Cannot save the current index state
~/projects/sms/apps2/apps2_admin(apps2)$ git pull
M   Gemfile
U   Gemfile.lock
Pull is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm <file>'
as appropriate to mark resolution, or use 'git commit -a'.
4

4 回答 4

82
git fetch origin
git reset --hard origin/master
git pull

解释:

  • Fetch 将从另一个存储库中下载所有内容,在这种情况下,标记为“origin”的那个。
  • 重置将丢弃更改并恢复到存储库“origin”中的提到的分支“master”。
  • Pull 只会从远程存储库中获取所有内容并进行集成。

请参阅http://git-scm.com/docs上的文档。

于 2014-08-22T18:26:51.763 回答
44

您可以使用git checkout <file>检查文件的已提交版本(从而丢弃您的更改),或丢弃git reset --hard HEAD所有文件的任何未提交更改。

于 2011-11-08T00:48:24.640 回答
2

我已经尝试了这两种方法,但由于冲突仍然失败。在耐心结束时,我将 master 克隆到另一个位置,将所有内容复制到另一个分支并提交。这让我继续。“-X theirs”选项应该为我完成了这个,但它没有。

git merge -s recursive -X 他们的主人

错误:“合并”是不可能的,因为您有未合并的文件。提示:在工作树中修复它们,提示:然后使用 'git add/rm' 作为提示:适合标记分辨率并进行提交,提示:或使用 'git commit -a'。致命的:由于未解决的冲突而退出。

于 2014-01-15T18:45:31.913 回答
1

我遇到了同样的错误,我用以下方法解决了它:git merge -s recursive -X theirs origin/master

于 2013-05-22T17:23:11.393 回答