首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将上游分支中的更改合并到我的fork分支

如何将上游分支中的更改合并到我的fork分支
EN

Stack Overflow用户
提问于 2018-10-25 11:52:35
回答 1查看 2.6K关注 0票数 2

我想从上游回购的分支中提取更改。我已经使用以下命令设置了上游回购:

代码语言:javascript
复制
git remote add upstream http://URL-of-master-repo.git 

然后,我尝试使用以下命令提取更改

代码语言:javascript
复制
git checkout my-local-branch
git fetch upstream remote-branch
git merge upstream/remote-branch

但是文件仍然没有出现在我的磁盘上,但是我得到了一个冲突:

代码语言:javascript
复制
Auto-merging minimal-build-config.cmake
CONFLICT (content): Merge conflict in minimal-build-config.cmake
Automatic merge failed; fix conflicts and then commit the result.

如何正确解决冲突,以便能够从上游分支获取文件?

EN

回答 1

Stack Overflow用户

发布于 2018-10-25 12:06:56

一个好的做法是拥有这样的结构,它看起来像你做的,但为了澄清的目的进行解释是很好的:

代码语言:javascript
复制
origin  https://github.com/your-username/forked-repository.git (fetch)
origin  https://github.com/your-username/forked-repository.git (push)
upstream    https://github.com/original-owner-username/original-repository.git (fetch)
upstream    https://github.com/original-owner-username/original-repository.git (push)

因此,origin是您的分支,而upstream是原始存储库。然后使用

代码语言:javascript
复制
git fetch upstream

你会得到下面的输出

代码语言:javascript
复制
From https://github.com/original-owner-username/original-repository
 * [new branch]      master     -> upstream/master

其中现在有一个名为upstream/master的分支,用于跟踪原始存储库。

然后结帐到您的本地分支并合并

代码语言:javascript
复制
git checkout master
git merge upstream/master

如果您有冲突(看起来是这样),修复它们并提交更改。

Source

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52981111

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档