【问题标题】:Git Merge IssuesGit 合并问题
【发布时间】:2015-10-07 10:30:31
【问题描述】:

我正在阅读 Michael Hartl 的“Ruby 教程”的第 5 章。我试图合并分支,在错误的分支上,把自己带进了兔子洞。在做了一些回溯之后,我已经走得很远了,但现在这又是我的问题了。

****Captains-iMac:sample_app owner$ git pull origin master
U   app/views/layouts/application.html.erb
U   app/views/static_pages/home.html.erb
U   config/routes.rb
U   test/controllers/static_pages_controller_test.rb
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 and make a commit.****

主分支是目前对我来说正确的分支。对一个完整的新手有什么建议吗?

【问题讨论】:

  • 我认为你必须手动合并文件以避免冲突。
  • 有几种方法可以解决您的问题。问题是你关心你的本地变化吗?或者你不介意丢弃它们。显示您的git status 输出
  • 在分支 master 你的分支和 'origin/master' 已经分道扬镳,分别有 4 和 2 个不同的提交。 (使用“git pull”将远程分支合并到你的)你有未合并的路径。 (修复冲突并运行“git commit”)未合并的路径:(使用“git add ...”来标记解析)都修改了:app/views/layouts/application.html.erb 都添加了:app/views/ static_pages/home.html.erb 均已修改:config/routes.rb 均已添加:test/controllers/static_pages_controller_test.rb 未添加任何更改以提交(使用“git add”和/或“git commit -a”)

标签: ruby-on-rails git


【解决方案1】:

您可以做的一件事是使用git checkout &lt;file&gt; 检查文件的已提交版本(从而丢弃您的更改),或使用git reset --hard HEAD 丢弃所有文件的任何未提交更改。

警告:后者将放弃您的所有本地更改。仅当您不特别关心您在本地所做的更改时才这样做。

否则,我鼓励您查看这个出色的 post,其中接受答案的作者深入介绍了您目前遇到的问题。

希望对你有所帮助。

【讨论】:

  • +1 表示@Tim Kos 引用的帖子。在 tut 中大致相同的地方看起来完全一样的错误。
  • 感谢蒂姆帮助我完成了我在这里的第一篇文章,非常感谢。
【解决方案2】:

这些是冲突的文件:

git pull origin master
U   app/views/layouts/application.html.erb
U   app/views/static_pages/home.html.erb
U   config/routes.rb
U   test/controllers/static_pages_controller_test.rb
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 and make a commit.

这正是我为修复它而输入的内容:

Captains-iMac:sample_app owner$ git add app/views/layouts/application.html.erb Captains-iMac:sample_app owner$ git add app/views/static_pages/home.html.erb Captains-iMac:sample_app owner$ git add config/routes.rb Captains-iMac:sample_app owner$ git add 测试/控制器/static_pages_controller_test.rb Captains-iMac:sample_app owner$ git commit -m "解决合并冲突" [master 891a992] 解决了合并冲突

【讨论】:

    猜你喜欢
    • 2012-01-18
    • 2021-04-25
    • 2012-07-16
    • 1970-01-01
    • 1970-01-01
    • 2013-01-15
    • 2018-10-10
    • 1970-01-01
    相关资源
    最近更新 更多