Git 的origin和master分析, 清空master分支

git操作

git删除master分支后重建

参考博客
首先你不能直接在要删除的master分支下删除master, 默认主分支是没办法删掉的, 所以你得把master设置成普通的分支, 然后才能删掉master分支,
怎么做呢? 你得新建一个分支 比如temp, 然后把temp设为默认的主分支, 然后就可以把master这个分支在 gitlab或github的网页中删掉了,
上述操作都可以在 网页中完后的, 一般更换默认主分支的命令在 project setting 选项里的,

Git 的origin和master分析

参考文档

在clone完成之后,Git 会自动为你将此远程仓库命名为origin(origin只相当于一个别名,运行git remote –v或者查看.git/config可以看到origin的含义),并下载其中所有的数据,建立一个指向它的master 分支的指针,我们用(远程仓库名)/(分支名) 这样的形式表示远程分支,所以origin/master指向的是一个remote branch(从那个branch我们clone数据到本地),但你无法在本地更改其数据。

同时,Git 会建立一个属于你自己的本地master 分支,它指向的是你刚刚从remote server传到你本地的副本。随着你不断的改动文件,git add, git commit,master的指向会自动移动,你也可以通过merge(fast forward)来移动master的指向。

$git branch -a (to show all the branches git knows about)

  • master

remotes/origin/HEAD -> origin/master

remotes/origin/master

$git branch -r (to show remote branches git knows about)

origin/HEAD -> origin/master

origin/master

可以发现,master就是local branch,origin/master是remote branch(master is a branch in the local repository. remotes/origin/master is a branch named master on the remote named origin)

$git diff origin/master master (show me the changes between the remote master branch and my master branch).

需要注意的是,remotes/origin/master和origin/master的指向是相同的

$git diff origin/master remotes/origin/master

git push origin master

origin指定了你要push到哪个remote

master其实是一个“refspec”,正常的“refspec”的形式为”+<src>:<dst>”,冒号前表示local branch的名字,冒号后表示remote repository下 branch的名字。注意,如果你省略了<dst>,git就认为你想push到remote repository下和local branch相同名字的branch。听起来有点拗口,再解释下,push是怎么个push法,就是把本地branch指向的commit push到remote repository下的branch,比如

$git push origin master:master (在local repository中找到名字为master的branch,使用它去更新remote repository下名字为master的branch,如果remote repository下不存在名字是master的branch,那么新建一个)

$git push origin master (省略了<dst>,等价于“git push origin master:master”)

$git push origin master:refs/for/mybranch (在local repository中找到名字为master的branch,用他去更新remote repository下面名字为mybranch的branch)

$git push origin HEAD:refs/for/mybranch (HEAD指向当前工作的branch,master不一定指向当前工作的branch,所以我觉得用HEAD还比master好些)

$git push origin :mybranch (再origin repository里面查找mybranch,删除它。用一个空的去更新它,就相当于删除了)

git 删除分支和删除文件夹

参考文档
删掉temp分支下的所有文件, 此时temp是默认主分支, 然后根据temp重新创建回来master分支, 然后重复 [git删除master分支后重建]
这个操作, 就可以了, 重新创建回来的master就是个空项目了。

在gitlab和github中可以在 project setting中更改 default branch

默认不一定非得是master, 也可以是其他, 比如新建分支temp, 把temp分支设置为 默认分支, 也就是主分支吧 , 不过按照约定俗称的说法, 还是以master作为默认的主分支。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值