Git 删除子模块/远程分支

Nov 3, 2020 · 1 min read

删除子模块

# 逆初始化模块,其中{MOD_NAME}为模块目录,执行后可发现模块目录被清空
git submodule deinit {MOD_NAME}
# 删除.gitmodules中记录的模块信息(--cached选项清除.git/modules中的缓存)
git rm --cached {MOD_NAME}
# 提交更改到代码库,可观察到'.gitmodules'内容发生变更
git commit -am "Remove a submodule."

修改某模块URL

  1. 修改’.gitmodules’文件中对应模块的”url“属性;
  2. 使用git submodule sync命令,将新的URL更新到文件.git/config;
$ git submodule sync # 运行后可观察到'.git/config'中对应模块的url属性被更新
Synchronizing submodule url for 'themes/hugo-clarity'
$ git commit -am "Update submodule url." # 提交变更

删除远程分支

git默认支持的操作方式

git push origin --delete [branch_name]

另一种方式,push一个分支到远程分支。

git push origin [local_branch_name]:[branch_name]

如果推送一个空的分支到远程,也会删除远程分支。

git push origin :[branch_name]
Bang
Authors
Professor of Artificial Intelligence
My research interests include distributed robotics, mobile computing and programmable matter.