1、創建分支(分支名為:office)
(python) [root@localhost xbiquge_w]# git branch office
2、切換分支
(python) [root@localhost xbiquge_w]# git checkout office
切換到分支 'office'
您的分支與上游分支 'origin/office' 一致。
#此命令執行后,本地文件在office分支狀態下看到的文件與在master分支狀態下看到的文件就不相同。
3、與遠程分支相關聯
(python) [root@localhost xbiquge_w]# git remote add origin https://github.com/sfccl/xbiquge_w.git
4、上傳分支
(python) [root@localhost xbiquge_w]# git push origin office
5、合並分支(把office分支合並到master)
(1)切換到master分支
(python) [root@localhost xbiquge_w]# git checkout master
已經位於 'master'
您的分支與上游分支 'origin/master' 一致。
(2)執行分支合並
(python) [root@localhost xbiquge_w]# git merge office
更新 dea3e33..c457b0c
Fast-forward
xbiquge/items.py | 2 ++
xbiquge/pipelines.py | 47 ++++++++++++++++++++++-------------------------
xbiquge/spiders/sancun.py | 5 ++++-
3 files changed, 28 insertions(+), 26 deletions(-)
此命令執行后,在本地查看,master下的相關文件已更改為與office下的文件相同了。但在遠程倉庫,文件還未合並。
(3)提交遠程更改
(python) [root@localhost xbiquge_w]# git status
位於分支 master
您的分支領先 'origin/master' 共 1 個提交。
(使用 "git push" 來發布您的本地提交)
無文件要提交,干凈的工作區
(python) [root@localhost xbiquge_w]# git push origin master
Username for 'https://github.com': sfccl
Password for 'https://sfccl@github.com':
Total 0 (delta 0), reused 0 (delta 0)
To https://github.com/sfccl/xbiquge_w.git
dea3e33..c457b0c master -> master
#此時,查看遠程github.com上的master分支,相關文件內容已發生了變化。
#反之,若新修改的是master分支,需要同步到office分支,則按上述方法,先切換到office分支,執行git merge master后,執行git push origin office即可。
6、版本回退
(1)查看各版本的ID號:
(python) [root@localhost xbiquge_w]# git log
commit 4ebccfe0f2e558f8c4a6476fa53f6edf2ced18ed (HEAD -> office, origin/office, origin/master, master)
Author: sfccl <sfccl@sina.com>
Date: Tue Oct 20 08:32:29 2020 +0800
move spider files
commit c457b0ce00796a9013b527cdf39f62ddb5a7589b
Author: sfccl <sfccl@sina.com>
Date: Mon Oct 19 09:31:56 2020 +0800
office push modify
commit dea3e3394d3aef42921306c4f082d64a3133ad6c
Author: sfccl <sfccl@sina.com>
Date: Mon Oct 19 08:32:06 2020 +0800
delete myspiders.log
...
(2)回退到版本號ID為c457b0ce00796a9013b527cdf39f62ddb5a7589b的版本
(python) [root@localhost xbiquge_w]# git reset --hard c457b0ce00796a9013b527cdf39f62ddb5a7589b
HEAD 現在位於 c457b0c office push modify
7、git clone與git pull的區別
git clone一定要在倉庫名(xbiquge_w)的上一級目錄(這是因為git clone是把xbiquge_w.git整個打包下來,這個包就包含了倉庫的最上級目錄xbiquge_w。)
git pull在倉庫名內執行。(git pull 實際是把遠端的xbiquge_w倉庫內的內容同步到本地xbiquge_w倉庫)