|
在github上看到好的开源项目可以fork成为自己的项目。但是如果fork的项目更新了自己的项目要怎样保持更新呢?
经过一番搜索后找到方法,下面记录下流程。
方法一:登录你的github帐号,选择fork的项目,点击左上角绿色的图标,鼠标放上去以后提示:compare ,review, create a pull reques。
方法二 :将fork后自己的项目clone到本地。
git clone https://github.com/name/libpcap.git
$ git remote -v
origin https://github.com/name/libpcap.git (fetch)
origin https://github.com/name/libpcap.git (push)
将fork之前的项目添加到本地的远程分支中,即作者的分支:
$ git remote add libpcap https://github.com/the-tcpdump-group/libpcap.git
$ git remote -v
libpcap https://github.com/the-tcpdump-group/libpcap.git (fetch)
libpcap https://github.com/the-tcpdump-group/libpcap.git (push)
origin https://github.com/name/libpcap.git (fetch)
origin https://github.com/name/libpcap.git (push)
同步
同步上游仓库到你的仓库需要执行两步:首先你需要从远程拉去,之后你需要合并你希望的分支到你的本地副本分支。
拉取
从远程仓库拉取将取回其分支以及各自的提交。它们将存储在你本地仓库的指定分之下。
$ git fetch libpcap
From https://github.com/the-tcpdump-group/libpcap
* [new branch] android-libpcap-0.9.8 -> libpcap/android-libpcap-0.9.8
* [new branch] bare -> libpcap/bare
* [new branch] lbl -> libpcap/lbl
* [new branch] libpcap-1.6 -> libpcap/libpcap-1.6
* [new branch] libpcap-1.7 -> libpcap/libpcap-1.7
* [new branch] libpcap_0_6 -> libpcap/libpcap_0_6
* [new branch] libpcap_0_7 -> libpcap/libpcap_0_7
* [new branch] libpcap_0_8 -> libpcap/libpcap_0_8
* [new branch] libpcap_0_8rel1 -> libpcap/libpcap_0_8rel1
* [new branch] libpcap_0_9 -> libpcap/libpcap_0_9
* [new branch] libpcap_1.1 -> libpcap/libpcap_1.1
* [new branch] libpcap_1.2 -> libpcap/libpcap_1.2
* [new branch] libpcap_1.3 -> libpcap/libpcap_1.3
* [new branch] libpcap_1.4 -> libpcap/libpcap_1.4
* [new branch] libpcap_1.5 -> libpcap/libpcap_1.5
* [new branch] libpcap_1_0 -> libpcap/libpcap_1_0
* [new branch] libpcap_1_0_rel0b -> libpcap/libpcap_1_0_rel0b
* [new branch] libpcap_1_4rel0 -> libpcap/libpcap_1_4rel0
* [new branch] linux-2-2-packet -> libpcap/linux-2-2-packet
* [new branch] master -> libpcap/master
* [new branch] origin -> libpcap/origin
git branch -av 列出本地分支和远程分支
-a 查看所有的分支
-v 查看各个分支最后一个提交对象的信息
$ git branch -av
* master 48aacf2 Merge pull request #433 from msekletar/master
remotes/libpcap/android-libpcap-0.9.8 91f35ab copy config.h from subdirectory on Android rather than run configure
remotes/libpcap/bare feab221 regenerated configure with --with-libnl switch
remotes/libpcap/lbl 9de7b67 pcap-0.4
remotes/libpcap/libpcap-1.6 4fec216 Fix previous change.
remotes/libpcap/libpcap-1.7 b846943 Fix check for <linux/if_bonding.h>.
remotes/libpcap/libpcap_0_6 6c7150d Update the version number.
remotes/libpcap/libpcap_0_7 85aac6d Get ready for libpcap 0.7.2
remotes/libpcap/libpcap_0_8 fec98c1 Corrected the definition of IN_EXPERIMENTAL (0xfxxxxxxx is the experimental space)
remotes/libpcap/libpcap_0_8rel1 9ad5954 spec file for 0.8
合并
现在我们已经拉取了上游仓库,我们将要合并其变更到我们的本地分支。这将使该分支与上游同步,而不会失去我们的本地更改。
$ git merge libpcap/master
Already up-to-date.
推送到服务器:
$ git push origin master
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 289 bytes, done.
Total 3 (delta 2), reused 0 (delta 0)
To git@github.com:name/libpcap.git
48aacf2..9556d05 master -> master
过一段时间后又需要同步项目了仅需要执行 git fetch libpcap 命令以下的操作即可。
参考:https://help.github.com/articles/syncing-a-fork/
|