Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
524 views
in Technique[技术] by (71.8m points)

git - 如何更新GitHub分叉存储库?(How do I update a GitHub forked repository?)

I recently forked a project and applied several fixes.

(我最近分叉了一个项目,并应用了多个修复程序。)

I then created a pull request which was then accepted.

(然后,我创建了一个请求请求,该请求随后被接受。)

A few days later another change was made by another contributor.

(几天后,另一位贡献者进行了另一项更改。)

So my fork doesn't contain that change.

(因此,我的前叉不包含该更改。)

How can I get that change into my fork?

(我怎样才能把零钱放到我的叉子上?)

Do I need to delete and re-create my fork when I have further changes to contribute?

(当我有其他更改要贡献时,是否需要删除并重新创建我的fork?)

Or is there an update button?

(还是有更新按钮?)

  ask by Lea Hayes translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In your local clone of your forked repository, you can add the original GitHub repository as a "remote".

(在您的分支存储库的本地克隆中,您可以将原始GitHub存储库添加为“远程”。)

("Remotes" are like nicknames for the URLs of repositories - origin is one, for example.) Then you can fetch all the branches from that upstream repository, and rebase your work to continue working on the upstream version.

((“ Remotes”就像是存储库URL的昵称-例如, origin是一个。)然后,您可以从该上游存储库中获取所有分支,并重新整理工作以继续使用上游版本。)

In terms of commands that might look like:

(在可能看起来像的命令方面:)

# Add the remote, call it "upstream":

git remote add upstream https://github.com/whoever/whatever.git

# Fetch all the branches of that remote into remote-tracking branches,
# such as upstream/master:

git fetch upstream

# Make sure that you're on your master branch:

git checkout master

# Rewrite your master branch so that any commits of yours that
# aren't already in upstream/master are replayed on top of that
# other branch:

git rebase upstream/master

If you don't want to rewrite the history of your master branch, (for example because other people may have cloned it) then you should replace the last command with git merge upstream/master .

(如果您不想重写master分支的历史记录(例如,因为其他人可能已经克隆了它),则应将最后一个命令替换为git merge upstream/master 。)

However, for making further pull requests that are as clean as possible, it's probably better to rebase.

(但是,为了发出更多尽可能干净的拉取请求,最好重新设置基准。)


If you've rebased your branch onto upstream/master you may need to force the push in order to push it to your own forked repository on GitHub.

(如果您已将分支重新建立到upstream/master ,则可能需要强制执行推送才能将其推送到GitHub上自己的分叉存储库中。)

You'd do that with:

(您可以这样做:)

git push -f origin master

You only need to use the -f the first time after you've rebased.

(重新设定基准后,您只需要在第一次使用-f 。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...