Git - 在 pull 请求之前修复主分支和功能分支之间的冲突

标签 git github branch pull

我必须向存储库发出 pull 请求。 我克隆了这个项目,它只有一个分支:master

我检查了一个新的分支 feature 并将我的更改提交到这个分支。

我将我的分支推送到 Github,现在我可以发出 pull 请求。所以我这样做了,但现在它告诉我我有冲突。 enter image description here

我明白这个问题。 master 领先于 feature,因为我在处理 feature 时没有“pull ”对 master 所做的最后更改。

我该如何解决?我怎样才能将 master 的最后更改“pull ”到我的 feature 分支中?

最佳答案

通过 merge 修复:

git fetch origin         # gets latest changes made to master
git checkout feature     # switch to your feature branch
git merge master         # merge with master
# resolve any merge conflicts here
git push origin feature  # push branch and update the pull request

通过 rebase 修复:

git fetch origin         # gets latest changes made to master
git checkout feature     # switch to your feature branch
git rebase master        # rebase your branch on master
# complete the rebase, fix merge conflicts, etc.
git push --force origin feature

请注意,由于 rebase 有效地重写了 feature 分支,因此可能需要 rebase 后推送的 --force 选项。这意味着您需要通过强制推送来覆盖 GitHub 中的旧分支。

无论您是进行 merge 还是 rebase ,之后都应该解决冲突,并且您的审阅者应该能够完成 pull 请求。

关于Git - 在 pull 请求之前修复主分支和功能分支之间的冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40864278/

相关文章:

git - 我可以在 .gitignore 文件中包含其他 .gitignore 文件吗? (就像类 C 语言中的#include)

git - 择优 merge 在此方案中是否合适?

github - 与 Gitlab 集成的 Upsource

git - 获取 git LFS 文件时出错 : Object does not exist on the server: [404] Object does not exist on the server

mercurial - 为什么 Mercurial 有时允许与祖先 merge ?

git 错误 : failed to push some refs to remote

python - 如何从 github 安装存储库?

git - SSH:SourceTree 推送失败

功能分支的 Git 工作流

version-control - TFS 中每个促销分支的权衡