Git 使用1:Git基本命令 https://blog.csdn.net/jiduochou963/article/details/86773455
Git 使用2:Git撤销操作 https://blog.csdn.net/jiduochou963/article/details/86777341
Git 使用3:Git文件删除 https://blog.csdn.net/jiduochou963/article/details/86889589
>
Git 使用4:Git分支 https://blog.csdn.net/jiduochou963/article/details/86908725
Git 使用5:Git远程仓库的搭建及使用 https://blog.csdn.net/jiduochou963/article/details/86936578
Git使用4:Git分支
Git分支的创建、修改、切换、删除
git branch
查看分支git branch branchname
创建分支git branch -m oldname newname
修改分支名称git checkout branchname
切换分支git checkout -b branchname
创建新分支并切换到新分支git branch -D branchname
删除分支
分支的合并
1、分支的指针
HEAD
指针指向当前工作的分支,在切换分支时指向新的分支
2、 git diff
git diff
比较工作区与暂存区文件的差异git diff -staged
比较暂存区与版本库的文本差异git diff 版本号1 版本号2
比较分支内的两个版本的差异git diff 分支1 分支2
比较两个分支的最新提交版本的差异
Git分支的创建、修改、切换、删除
git branch
git branch
查看分支
ONEFINE@ONE-FINE MINGW64 ~/Desktop/Demo (master)
$ git status
On branch master
nothing to commit, working tree clean
ONEFINE@ONE-FINE MINGW64 ~/Desktop/Demo (master)
$ git branch
* master
ONEFINE@ONE-FINE MINGW64 ~/Desktop/Demo (master)
$
标明我们现在处于master分支,且git目前有且仅有一个master分支。
git branch branchname
git branch branchname
创建新分支
ONEFINE@ONE-FINE MINGW64 ~/Desktop/Demo (master)
$ git branch dev
ONEFINE@ONE-FINE MINGW64 ~/Desktop/Demo (master)
$ git branch
dev
* master
ONEFINE@ONE-FINE MINGW64 ~/Desktop/Demo (master)
$
显示我们创建了dev分支,但当前我们仍处于master分支。
git checkout [-b] branchname
git checkout branchname
切换分支
ONEFINE@ONE-FINE MINGW64 ~/Desktop/Demo (master)
$ git checkout dev
Switched to branch 'dev'
ONEFINE@ONE-FINE MINGW64 ~/Desktop/Demo (dev)
$ git branch
* dev
master
ONEFINE@ONE-FINE MINGW64 ~/Desktop/Demo (dev)
$
git checkout -b branchname
创建新分支并切换
![](/qrcode.jpg)
ONEFINE@ONE-FINE MINGW64 ~/Desktop/Demo (master)
$ git checkout -b dev
Switched to a new branch 'dev'
ONEFINE@ONE-FINE MINGW64 ~/Desktop/Demo (dev)
$ git branch
* dev
master
ONEFINE@ONE-FINE MINGW64 ~/Desktop/Demo (dev)
$
git branch -D branchname
git branch -D branchname
删除分支
ONEFINE@ONE-FINE MINGW64 ~/Desktop/Demo (dev)
$ git branch -d dev
error: Cannot delete branch 'dev' checked out at 'C:/Users/ONEFINE/Desktop/Demo'
ONEFINE@ONE-FINE MINGW64 ~/Desktop/Demo (dev)
$
提示删除错误,因为我们现在处于dev分支上;如果想删除一个分支,必须切换到另外一个分支上:
ONEFINE@ONE-FINE MINGW64 ~/Desktop/Demo (dev)
$ git checkout master
Switched to branch 'master'
ONEFINE@ONE-FINE MINGW64 ~/Desktop/Demo (master)
$ git branch
dev
* master
ONEFINE@ONE-FINE MINGW64 ~/Desktop/Demo (master)
$ git branch -d dev
Deleted branch dev (was e001d77).
ONEFINE@ONE-FINE MINGW64 ~/Desktop/Demo (master)
$ git branch
* master
ONEFINE@ONE-FINE MINGW64 ~/Desktop/Demo (master)
$
git branch -m oldname newname
git branch -m oldname newname
修改分支名称
ONEFINE@ONE-FINE MINGW64 ~/Desktop/Demo (master)
$ git branch -m master master1
ONEFINE@ONE-FINE MINGW64 ~/Desktop/Demo (master1)
$ git branch
* master1
ONEFINE@ONE-FINE MINGW64 ~/Desktop/Demo (master1)
$ git branch -m master1 master
ONEFINE@ONE-FINE MINGW64 ~/Desktop/Demo (master)
$
分支的合并
1、分支的指针