本文共 3819 字,大约阅读时间需要 12 分钟。
git fork库同步代码
You're contributing to an open-source project, and you noticed that your fork is out of sync with the original repository. How can you correct that?
您正在为一个开源项目做贡献,并且注意到您的fork与原始存储库不同步。 您该如何纠正?
# Add a new remote upstream repositorygit remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git# Sync your forkgit fetch upstreamgit checkout mastergit merge upstream/master
You cloned your fork on your laptop and started to work on your issue.
您在笔记本电脑上克隆了叉子,并开始解决您的问题。
Did you know that your fork is an orphan? If you list the configured remote repository you will only see your fork as origin:
你知道你的叉子是孤儿吗? 如果列出已配置的远程存储库,则只会看到派生作为源:
git remote -vorigin https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)
There are no signs of parents! Where is the original repository?
没有父母的迹象! 原始存储库在哪里?
We need to configure this information to restore the family relationship by adding a new remote upstream repository:
我们需要配置此信息以通过添加新的远程上游存储库来恢复家族关系:
git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
You saved the family! You can now see both the original repository and the fork:
你救了家人! 现在,您可以同时看到原始存储库和分支:
git remote -vorigin https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (fetch)upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (push)
Everything is now set up. You can sync your fork with only 2 commands.
现在一切都已设置。 您只能使用2个命令来同步fork。
Be sure you're in the root of your project and also in the master branch. Otherwise, you can check out to the master branch:
确保您既在项目的根目录中,又在master分支中。 否则,您可以签出到master分支:
git checkout masterSwitched to branch 'master'
Now, you have to fetch the changes from the original repository:
现在,您必须从原始存储库中获取更改:
git fetch upstreamremote: Enumerating objects: 16, done.remote: Counting objects: 100% (16/16), done.remote: Compressing objects: 100% (7/7), done.remote: Total 7 (delta 5), reused 0 (delta 0), pack-reused 0Unpacking objects: 100% (7/7), 1.72 Kio | 160.00 Kio/s, done.From https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY 909ef5a..0b228a8 master -> upstream/master
And merge the changes in your master branch:
并在您的master分支中合并更改:
git merge upstream/masterUpdating 909ef5a..0b228a8Fast-forward node.js/WorkingWithItems/batch-get.js | 51 ++++++++++++++++++++++++++------------------------ node.js/WorkingWithItems/batch-write.js | 95 +++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------- node.js/WorkingWithItems/delete-item.js | 37 ++++++++++++++++++------------------ node.js/WorkingWithItems/get-item.js | 31 +++++++++++++++++-------------- node.js/WorkingWithItems/put-item-conditional.js | 51 +++++++++++++++++++++++++------------------------- node.js/WorkingWithItems/put-item.js | 49 ++++++++++++++++++++++++------------------------ node.js/WorkingWithItems/transact-get.js | 51 ++++++++++++++++++++++++++------------------------ node.js/WorkingWithItems/transact-write.js | 79 ++++++++++++++++++++++++++++++++++++++++------------------------------------- node.js/WorkingWithItems/update-item-conditional.js | 51 ++++++++++++++++++++++++++------------------------ node.js/WorkingWithItems/update-item.js | 47 ++++++++++++++++++++++++---------------------- 10 files changed, 282 insertions(+), 260 deletions(-)
That's it! Your fork is now up to date.
而已! 您的叉子现在是最新的。
Any questions? Feel free to contact me on !
任何问题? 随时通过与我联系!
翻译自:
git fork库同步代码
转载地址:http://bmgwd.baihongyu.com/