Git增加子模块submodule


 通过 git submodule add命令引入子模块,命令如下:

git submodule add http://xxx.xxx.xxx/xxx.git ./sub/dir

 在子模块中修改和提交代码,直接提交至子模块自身git

 

 通过 git rm 删除子模块,删除命令如下

 git rm -f submodule_name         #同时删除本地文件
 或
 git rm --cached submodule_name   #保留本地文件

  

 第一次使用时,错误的将本地代码add至当前repo (git submodule add ./local/code/dir ./sub/dir)导致无法push子模块,提示如下错误:

remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error: 
remote: error: You can set 'receive.denyCurrentBranch' configuration variable t
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing int
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in som
remote: error: other way.
remote: error: 
remote: error: To squelch this message and still keep the default behaviour, se
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.

 重新add 远程git路径得以解决

参考链接:

http://a.ghuser.io/git-pushing-a-new-submodule/

https://git-scm.com/docs/git-submodule

https://git-scm.com/book/zh/v2/Git-%E5%B7%A5%E5%85%B7-%E5%AD%90%E6%A8%A1%E5%9D%97

https://stackoverflow.com/questions/6414675/git-pushing-submodule


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM