将主分支变基到功能分支,变基后再次发生冲突
Rebasing a master branch onto a feature branch, getting conflicts again after rebase
我有一个功能分支是前段时间从 master 那里拿来的。现在我想将 master 变基到那个特性分支上,所以我做了这个命令:
git rebase master
然后我继续使用 SourceTree,因为我遇到了冲突。我一个一个解决了,然后继续rebase,这样持续了一段时间。终于很高兴一切似乎都完成了。
这是 Sourcetree 现在向我展示的内容:
当我运行
git rebase master
我明白了
Current branch 2FA is up to date.Current branch 2FA is up to date.
当我这样做时:
git pull
我得到了我必须重新做的文件列表。
Auto-merging db/schema.rb
CONFLICT (content): Merge conflict in db/schema.rb
Auto-merging config/locales/nl.yml
CONFLICT (content): Merge conflict in config/locales/nl.yml
Auto-merging app/views/users/_form.html.haml
CONFLICT (content): Merge conflict in app/views/users/_form.html.haml
Auto-merging app/models/user.rb
CONFLICT (content): Merge conflict in app/models/user.rb
Auto-merging app/models/permission.rb
CONFLICT (content): Merge conflict in app/models/permission.rb
Auto-merging app/helpers/application_helper.rb
CONFLICT (content): Merge conflict in app/helpers/application_helper.rb
Auto-merging app/controllers/users_controller.rb
CONFLICT (modify/delete): app/controllers/companies_controller.rb deleted in HEAD and modified in 1110e1f18d4ab388eab767509d95be10b9953a36. Version 1110e1f18d4ab388eab767509d95be10b9953a36 of app/controllers/companies_controller.rb left in tree.
Auto-merging app/assets/stylesheets/custom.css.sass
CONFLICT (content): Merge conflict in app/assets/stylesheets/custom.css.sass
Auto-merging app/assets/stylesheets/backapp.css
CONFLICT (content): Merge conflict in app/assets/stylesheets/backapp.css
Auto-merging Gemfile.lock
CONFLICT (content): Merge conflict in Gemfile.lock
Auto-merging Gemfile
CONFLICT (content): Merge conflict in Gemfile
Automatic merge failed; fix conflicts and then commit the result.
这是为什么?我已经做了解决这个问题的工作。这种方式 rebase 似乎比合并要多得多。
当您将功能分支重新定位于 master
时,您重写了该分支的历史记录。实际发生的是您在 master
分支上重放了您的工作。一旦你完成了 rebase,正常的做法是将你的功能分支强制推送到远程:
git push --force origin feature
当您执行 git pull
时发生的事情是您告诉 Git 引入当前的远程 feature
分支,大概是通过合并策略。由于您刚刚重写了 feature
分支,因此 Git 将远程分支视为 "new," 至少在合并应该发生方面。无论如何,做 git pull
是不正确的,您可能需要的只是强制推送您的功能分支。
如果你想知道为什么你甚至想使用 rebase 而不是合并,事实证明 rebase 有能力在功能分支中维护线性历史。这可能是有利的,因为它使分支的历史易于阅读。缺点是每个使用这个分支的人可能需要通过变基做更多的工作。
我有一个功能分支是前段时间从 master 那里拿来的。现在我想将 master 变基到那个特性分支上,所以我做了这个命令:
git rebase master
然后我继续使用 SourceTree,因为我遇到了冲突。我一个一个解决了,然后继续rebase,这样持续了一段时间。终于很高兴一切似乎都完成了。
这是 Sourcetree 现在向我展示的内容:
当我运行
git rebase master
我明白了
Current branch 2FA is up to date.Current branch 2FA is up to date.
当我这样做时:
git pull
我得到了我必须重新做的文件列表。
Auto-merging db/schema.rb
CONFLICT (content): Merge conflict in db/schema.rb
Auto-merging config/locales/nl.yml
CONFLICT (content): Merge conflict in config/locales/nl.yml
Auto-merging app/views/users/_form.html.haml
CONFLICT (content): Merge conflict in app/views/users/_form.html.haml
Auto-merging app/models/user.rb
CONFLICT (content): Merge conflict in app/models/user.rb
Auto-merging app/models/permission.rb
CONFLICT (content): Merge conflict in app/models/permission.rb
Auto-merging app/helpers/application_helper.rb
CONFLICT (content): Merge conflict in app/helpers/application_helper.rb
Auto-merging app/controllers/users_controller.rb
CONFLICT (modify/delete): app/controllers/companies_controller.rb deleted in HEAD and modified in 1110e1f18d4ab388eab767509d95be10b9953a36. Version 1110e1f18d4ab388eab767509d95be10b9953a36 of app/controllers/companies_controller.rb left in tree.
Auto-merging app/assets/stylesheets/custom.css.sass
CONFLICT (content): Merge conflict in app/assets/stylesheets/custom.css.sass
Auto-merging app/assets/stylesheets/backapp.css
CONFLICT (content): Merge conflict in app/assets/stylesheets/backapp.css
Auto-merging Gemfile.lock
CONFLICT (content): Merge conflict in Gemfile.lock
Auto-merging Gemfile
CONFLICT (content): Merge conflict in Gemfile
Automatic merge failed; fix conflicts and then commit the result.
这是为什么?我已经做了解决这个问题的工作。这种方式 rebase 似乎比合并要多得多。
当您将功能分支重新定位于 master
时,您重写了该分支的历史记录。实际发生的是您在 master
分支上重放了您的工作。一旦你完成了 rebase,正常的做法是将你的功能分支强制推送到远程:
git push --force origin feature
当您执行 git pull
时发生的事情是您告诉 Git 引入当前的远程 feature
分支,大概是通过合并策略。由于您刚刚重写了 feature
分支,因此 Git 将远程分支视为 "new," 至少在合并应该发生方面。无论如何,做 git pull
是不正确的,您可能需要的只是强制推送您的功能分支。
如果你想知道为什么你甚至想使用 rebase 而不是合并,事实证明 rebase 有能力在功能分支中维护线性历史。这可能是有利的,因为它使分支的历史易于阅读。缺点是每个使用这个分支的人可能需要通过变基做更多的工作。