您的位置:首页 > 编程语言

github更新自己Fork的代码

2016-08-22 00:00 190 查看
github上有个功能叫fork,可以将别人的工程复制到自己账号下。

这个功能很方便,但其有一个缺点是:当源项目更新后,你fork的分支并不会一起更新,需要自己手动去更新。

以gitHub用户:lyt-Python(组织名或者用户名),fork 项目scrapy(https://github.com/scrapy/scrapy.Git)为例子:

1、clone 自己账号里fork的分支

git clone https://github.com/lyt-python/scrapy.git[/code] 
cd scrapy

2、增加远程原始分支到本地(可以用
git remote -v
命令查看远程分支列表)

git remote -v
origin  https://github.com/lyt-python/scrapy.git (fetch)
origin  https://github.com/lyt-python/scrapy.git (push)

如果没有远程原始分支则需要增加:

git remote add scrapy https://github.com/scrapy/scrapy.git

查看确认远程分支列表:

git remote -v
origin  https://github.com/lyt-python/scrapy.git (fetch)
origin  https://github.com/lyt-python/scrapy.git (push)
scrapy  https://github.com/scrapy/scrapy.git (fetch)
scrapy  https://github.com/scrapy/scrapy.git (push)

3、fetch原始源分支的新版本到本地

git fetch scrapy

会有如下信息:

remote: Counting objects: 2147, done.

remote: Compressing objects: 100% (11/11), done.

remote: Total 2147 (delta 1280), reused 1280 (delta 1280), pack-reused 856

Receiving objects: 100% (2147/2147), 490.60 KiB | 39.00 KiB/s, done.

Resolving deltas: 100% (1585/1585), completed with 204 local objects.

From https://github.com/scrapy/scrapy
* [new branch] 0.12 -> scrapy/0.12

* [new branch] 0.14 -> scrapy/0.14

...

* [new tag] 1.2.0dev2 -> 1.2.0dev2

4、合并两个版本的代码

git merge scrapy/master

会有如下信息:

Updating a5db7f8..ebef6d7

Fast-forward

.bumpversion.cfg | 2 +-

.travis.yml | 7 +-

CODE_OF_CONDUCT.md | 50 ++++

...

...

create mode 100644 scrapy/xlib/pydispatch.py

create mode 100644 tests/test_pydispatch_deprecated.py

5、把最新的代码提交到github自己(lyt-python)的账号上

git push origin master

会有如下信息:

Counting objects: 1802, done.

Delta compression using up to 24 threads.

Compressing objects: 100% (558/558), done.

Writing objects: 100% (1802/1802), 280.30 KiB | 0 bytes/s, done.

Total 1802 (delta 1395), reused 1644 (delta 1241)

To https://github.com/lyt-python/scrapy.git
a5db7f8..ebef6d7 master -> master
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: