GitHub自己倉庫fork的專案與開源專案的程式碼保持一致
阿新 • • 發佈:2018-12-25
步驟(此處用的是Alibaba/fastjson):
1.將開源專案fork到自己賬號下的倉庫中;
2.將自己倉庫中fork的專案clone到本地;
3.
clone
需要將遠端倉庫clone到本地,此處省略安裝本地github的過程,隨便在哪個目錄(專案存放的目錄),右鍵開啟一個Git base,執行一下git clone https://github.com/***/***.git
4.上面的命令完成後,當前目錄下會多一個目錄,我clone的是fastjson,所以會多一個fastjson目錄,進到fastjson目錄中,試試跑一下git status
試試,會提示現在是master分支。
5.用git remote -v
6.
還需要與上游建立連線,這裡上游指的是一開始fork的那個專案源,以flink為例,執行如下命令:
git remote add upstream https://github.com/apache/flink.git
再用git remote -v
可以看到.
此處我自己的倉庫的程式碼是很久以前fork的,所以提交落後原始碼alibaba/master很多;一些步驟使自己倉庫分支與alibaba/master
程式碼保持一致
7.先fetch : git fetch upstream
8.再rebase :git rebase upstream/master
9.最後再push master
push完後,遠端倉庫便可看到你的branch版本和master分支一致了,否則這個位置會顯示與master相差了多少次commit
命令操作步驟:
[email protected] MINGW64 /f/WorkSpace/fastjson (master)
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
[email protected] MINGW64 /f/WorkSpace/fastjson (master)
$ git remote -v
origin https://github.com/canglang1973/fastjson.git (fetch)
origin https://github.com/canglang1973/fastjson.git (push)
[email protected] MINGW64 /f/WorkSpace/fastjson (master)
$ git remote add upstream https://github.com/alibaba/fastjson.git
[email protected] MINGW64 /f/WorkSpace/fastjson (master)
$ git remote -v
origin https://github.com/canglang1973/fastjson.git (fetch)
origin https://github.com/canglang1973/fastjson.git (push)
upstream https://github.com/alibaba/fastjson.git (fetch)
upstream https://github.com/alibaba/fastjson.git (push)
[email protected] MINGW64 /f/WorkSpace/fastjson (master)
$ git fetch upstream
remote: Counting objects: 3944, done.
remote: Compressing objects: 100% (14/14), done.
remote: Total 3944 (delta 1655), reused 1673 (delta 1655), pack-reused 2271
Receiving objects: 100% (3944/3944), 681.27 KiB | 21.00 KiB/s, done.
Resolving deltas: 100% (1903/1903), completed with 285 local objects.
From https://github.com/alibaba/fastjson
* [new branch] 1.1.33-android -> upstream/1.1.33-android
* [new branch] 1.1.42_android -> upstream/1.1.42_android
* [new branch] 1.1.43-android -> upstream/1.1.43-android
* [new branch] 1.1.44 -> upstream/1.1.44
* [new branch] 1.1.44-android -> upstream/1.1.44-android
* [new branch] 1.1.45 -> upstream/1.1.45
* [new branch] 1.1.45-android -> upstream/1.1.45-android
* [new branch] 1.1.46 -> upstream/1.1.46
* [new branch] 1.1.46-android -> upstream/1.1.46-android
* [new branch] android -> upstream/android
* [new branch] dev-1.2.0 -> upstream/dev-1.2.0
* [new branch] master -> upstream/master
* [new branch] revert-1513-master -> upstream/revert-1513-master
* [new tag] 1.1.64.android -> 1.1.64.android
* [new tag] 1.1.65.android -> 1.1.65.android
* [new tag] 1.1.66.android -> 1.1.66.android
* [new tag] 1.1.67.android -> 1.1.67.android
* [new tag] 1.1.68.android -> 1.1.68.android
* [new tag] 1.2.39 -> 1.2.39
* [new tag] 1.2.40 -> 1.2.40
* [new tag] 1.2.41 -> 1.2.41
* [new tag] 1.2.42 -> 1.2.42
* [new tag] 1.2.43 -> 1.2.43
* [new tag] 1.2.44 -> 1.2.44
* [new tag] 1.2.45 -> 1.2.45
* [new tag] 1.2.46 -> 1.2.46
* [new tag] 1.2.47 -> 1.2.47
[email protected] MINGW64 /f/WorkSpace/fastjson (1.1.44)
$ git rebase upstream/master
First, rewinding head to replay your work on top of it...
Fast-forwarded 1.1.44 to upstream/master.
[email protected] MINGW64 /f/WorkSpace/fastjson (1.1.44)
$ git rebase upstream/master
First, rewinding head to replay your work on top of it...
Fast-forwarded master to upstream/master.
[email protected] MINGW64 /f/WorkSpace/fastjson (master)
$ git fetch upstream
[email protected] MINGW64 /f/WorkSpace/fastjson (master)
$ git push origin master
Fatal: AggregateException encountered.
Username for 'https://github.com': canglang1973
Counting objects: 3375, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (1681/1681), done.
Writing objects: 100% (3375/3375), 440.81 KiB | 0 bytes/s, done.
Total 3375 (delta 1606), reused 3126 (delta 1378)
remote: Resolving deltas: 100% (1606/1606), completed with 139 local objects.
To https://github.com/canglang1973/fastjson.git
0818ecf..c18836b master -> master
[email protected] MINGW64 /f/WorkSpace/fastjson (master)
$
參考:https://blog.csdn.net/vim_wj/article/details/78300239