git多分支的使用

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仓库)

原文地址:https://www.cnblogs.com/sfccl/p/13838963.html