Git中子模块的使用

Git中子模块的使用

提炼用法

how to create submodule relations?                                                             
    git clone ssh://git@3917f6dff4e8:20022/zhilan/sensor/tt.git                                    
    git submodule add ssh://git@3917f6dff4e8:20022/zhilan/sensor/tt1.git sub                       
    git submodule add -b dev ssh://git@3917f6dff4e8:20022/zhilan/sensor/tt1.git sub2               
    git add .gitmodules sub2 sub
                                                                        
    git push origin master                                                                         
                                                                                                   
                                                                                            
how to use submodule relations?                                                                                                                                               
    git clone ssh://git@3917f6dff4e8:20022/zhilan/sensor/tt.git tt_rename                                 
    git submodule init && git submodule update  --merge  --remote  
 
  	注意,不要只是执行git submodule update,   
    因为,如果没有--merge, 只相当于拉一下不能提交修改的快照(snap)                                           
                                                                                                   
    或                                                                                             
    git clone --recursive  ssh://git@3917f6dff4e8:20022/zhilan/sensor/tt.git t1                    
                                                                                                   
    开发过程中,如何需要同步依赖库的更新?                                                          
    git submodule update --remote    

how to modify submodule?
method1

*  in module path, 
*  vim code in module
*  git push origin master 

method2

*  in module path
*  vim code     
*  git push --recurse-submodules=check   

!注意有时子模块git push失败, 显示“HEAD detach from blabla... ”  
这是因为执行了git submodule update命令的原因,这个命令类似于git clone -b [tag_name]  
只是获取一个镜像,不能修改(没有建立与git的版本信息)  

如何修复呢?  
git submodule update --merge                                                         

扩展阅读

git HEAD的意义,detach的意义

HEAD 处于游离状态时,我们可以很方便地在历史版本之间互相切换,比如需要回到某次提交,直接 checkout 对应的 commit id 或者 tag 名即可。 .e.g:

git checkout

它的弊端就是:在这个基础上的提交会新开一个匿名分支
解决办法就是新建个分支保存游离状态后的提交:

git checkout -b new_branch_name

猜你喜欢

转载自blog.csdn.net/zhai_865327/article/details/106903506