删除分支
如果要删除分支中进行了一些开发动作,此时执行上面的删除命令并不会删除分支,如果坚持要删除此分支,可以将命令中的-d参数改为-D
Andrewer@CaesarGattuso MINGW64 /d/BaiduNetdiskDownload/gitRepository/test01 (b1)
$ git branch
* b1
b2
b3
b4
b5
master
Andrewer@CaesarGattuso MINGW64 /d/BaiduNetdiskDownload/gitRepository/test01 (b1)
$ git branch -d b2
Deleted branch b2 (was 1e63530).
Andrewer@CaesarGattuso MINGW64 /d/BaiduNetdiskDownload/gitRepository/test01 (b1)
$ git branch
* b1
b3
b4
b5
master
b2分支就没有了,但是删除的只是本地分支
在b1中修改User.java
Andrewer@CaesarGattuso MINGW64 /d/BaiduNetdiskDownload/gitRepository/test01 (b1)
$ git add User.java
Andrewer@CaesarGattuso MINGW64 /d/BaiduNetdiskDownload/gitRepository/test01 (b1)
$ git add User.java.bak
Andrewer@CaesarGattuso MINGW64 /d/BaiduNetdiskDownload/gitRepository/test01 (b1)
$ git commit -m "update User.java in baranch b"
[b1 5535d3e] update User.java in baranch b
2 files changed, 4 insertions(+), 3 deletions(-)
加入Staged,提交
Andrewer@CaesarGattuso MINGW64 /d/BaiduNetdiskDownload/gitRepository/test01 (b1)
$ git checkout master
Switched to branch 'master'
Andrewer@CaesarGattuso MINGW64 /d/BaiduNetdiskDownload/gitRepository/test01 (master)
$
切换到master分支中
Andrewer@CaesarGattuso MINGW64 /d/BaiduNetdiskDownload/gitRepository/test01 (master)
$ git branch -d b1
error: The branch 'b1' is not fully merged.
If you are sure you want to delete it, run 'git branch -D b1'.
Andrewer@CaesarGattuso MINGW64 /d/BaiduNetdiskDownload/gitRepository/test01 (master)
$
删除b1失败
因为刚才修改了b1中的java文件
修改之后,并没有推送到远程仓库中
The branch ‘b1’ is not fully merged.没有充分的合并
If you are sure you want to delete it, run ‘git branch -D b1’.如果坚持,那么可以将d 变为D
Andrewer@CaesarGattuso MINGW64 /d/BaiduNetdiskDownload/gitRepository/test01 (master)
$ git branch -D b1
Deleted branch b1 (was 5535d3e).
删除成功
在实际操作中不建议这样去做,有风险
在删除分支之前,应该推送到远程仓库中,或者合并到其他分支中
保证新添加的内容不要丢失
如果要删除远程仓库中的分支,可以使用命令
git push origin -d branchName
Andrewer@CaesarGattuso MINGW64 /d/BaiduNetdiskDownload/gitRepository/test01 (master)
$ git push origin -d b1
remote: Powered by GITEE.COM [GNK-6.4]
To https://gitee.com/doreamen-ac/test01.git
- [deleted] b1
Andrewer@CaesarGattuso MINGW64 /d/BaiduNetdiskDownload/gitRepository/test01 (master)
$
-d:delete
Andrewer@CaesarGattuso MINGW64 /d/BaiduNetdiskDownload/gitRepository/test01 (master)
$ git push origin -d b2
remote: Powered by GITEE.COM [GNK-6.4]
To https://gitee.com/doreamen-ac/test01.git
- [deleted] b2
Andrewer@CaesarGattuso MINGW64 /d/BaiduNetdiskDownload/gitRepository/test01 (master)
$
删除b2分支
远程仓库中显示404