通过子模块显示Git中的外部代码依赖性 [英] To show external code dependency in Git by a submodule

查看:144
本文介绍了通过子模块显示Git中的外部代码依赖性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

已解决的问题:通过子模块显示外部代码依赖关系:感谢 VonC



当前问题:拥有两个文件夹中没有重复内容的子模块

解决当前问题的临时解决方案:将文件夹的名称更改为bin-github,因为作为子模块的文件夹是bin。这意味着我需要在家中复制内容。



我的HOME文件夹依赖于〜/ bin。
我在Github的仓库 Masi 的HOME上找到了文件,而在〜/ bin下的仓库中找到了 bin 。我在家中的相关文件夹结构:

 
| - [drwxr-xr-x] bin
| - fileA
` - folderA
...

我想知道如何在 中显示make〜/ bin Git的子模块。



你怎么能让〜/ bin a我的Git子模块在〜/?






#3回复VonC评论: strong>



我的.gitmodules

  [submodulebin] 
path = bin
url = git://github.com/masi/bin.git

我觉得我不需要再次添加submodule,因为我已经在我的.gitmodules中。



我运行

  Sam master $ git submodule update 
Sam master $ git submodule foreach git pull
Sam master $ ls bin






#2回复VonC的回答:



我将.gitmodules更改为以下内容,以便我没有它的重复副本我的家。
$ b $ pre $ [submodulebin]
path = bin
url = git:/ /github.com/masi/bin.git

这似乎是一种不同的情况,因为我无法拉子模块 - 文件夹类似于上述。

现在我得到以下新鲜克隆的git-repo

  Sam master $ git submodule git init 
错误:pathspec'git'与git已知的任何文件都不匹配。
错误:pathspec'init'与git已知的任何文件都不匹配。
你忘了'git add'吗? #我不确定这意味着什么
Sam master $ git submodule foreach git pull
Sam master $ git submodule update

我的.gitmodules中有外部存储库。为什么要求我 git add






回复VonC的回答:



我运行

  git submodule add git://github.com/masi/bin.git bin-github-copy 

因为我无法添加一个新的回购库,其名称与我的现有文件夹 bin



我的.gitmodules是
$ b

  [submodulebin-github-copy] 
path = bin-github-copy
url = git://github.com/masi/bin.git

我运行

  git clone git://github.com/masi/Sam.git 

我得到一个emty bin目录。



如何获取bin的内容?

然后您有两个选择:




  • 子模块,以便Masi能够在] bin目录中引用 [文件的特定提交在GitHub(或者分支的最新提交,存储在GitHub上)

  • 子树合并,以便将两个存储库混合在一起,并更容易地对bin中的文件进行修改直接来自Masi存储库。这可能会更简单。 / 899373 /转让遗产代码基地从cvs的分布式存储库,例如git或mer / 899428#899428>这个答案更多关于这两种策略。






    在子模块路径上,声明子模块只是工作的一半。您仍然必须首次初始化子模块

      git submodule git init 

    您需要 pull your submodules

      git submodule foreach git pull 


    $ b

    然后更新你的子模块

      git submodule update 

    另见 Git submodules,part I and Git子模块,第二部分 $ b


    .gitmodules 文件仅存储路径,但提交版本与主项目存储在一起。

    我创建了一个 GitHub上的项目来演示发生了什么。请特别注意此提交,它添加了子模块,以查看发生了什么:




      +子项目提交60be4b09f51d2560802ebd744893bb6f737ef57c 


    Solved Problem: to show external code dependency by submodules: Thanks to VonC!

    Current Problem: to have a submodule without duplicate contents in two folders

    A temporary solution to the current problem: to change the name of the folder to bin-github, since the name of the folder as a submodule is bin. This means I need to duplicate contents at my Home.

    My HOME folder is dependent on ~/bin. I have files located at HOME at the repository Masi, while at ~/bin at the repo bin at Github. My relevant folder structure at Home:

    ~
    |-- [drwxr-xr-x] bin
        | -- fileA
        ` -- folderA
        ...
    

    I would like to know how to show make ~/bin a submodule of the Git at Masi.

    How can you make ~/bin a submodule of my Git at ~/ ?


    #3 Reply to VonC's comment:

    My .gitmodules

    [submodule "bin"]   
             path = bin
             url = git://github.com/masi/bin.git
    

    I feel that I do not need to add anymore the submodule again, since I have it in my .gitmodules.

    I run

    Sam master $ git submodule update
    Sam master $ git submodule foreach git pull
    Sam master $ ls bin 
    


    #2 Reply to VonC's answer:

    I changed my .gitmodules to the following such that I do not have a duplicate copy of it in my home.

    [submodule "bin"]
        path = bin
        url = git://github.com/masi/bin.git
    

    This seems to be a different situation as I cannot pull the submodule-bin -folder similarly as above.

    I get the following now at a fresh-cloned git-repo

    Sam master $ git submodule git init
    error: pathspec 'git' did not match any file(s) known to git.
    error: pathspec 'init' did not match any file(s) known to git.
    Did you forget to 'git add'?                          # I am not sure what this means
    Sam master $ git submodule foreach git pull
    Sam master $ git submodule update
    

    I have the external repository in my .gitmodules. Why is it asking me to git add?


    Reply to VonC's answer:

    I run

    git submodule add git://github.com/masi/bin.git bin-github-copy
    

    because I cannot add a new repo with the same name as my existing folder bin.

    My .gitmodules is

    [submodule "bin-github-copy"]
        path = bin-github-copy
        url = git://github.com/masi/bin.git
    

    I run

    git clone git://github.com/masi/Sam.git
    

    I get an emty bin -directory.

    How can I get the content of bin?

    解决方案

    First, do not forget that with Git, you can not "add" a directory, only the content of at least one file within that directory.

    Then you have two choices:

    • submodules, in order for Masi to refer a specific commit of your [files within a] bin directory stored at GitHub (or to the latest commit of a branch, stored at GitHub)

    • subtree merge, in order to mix the two repositories together and more easily follow modifications to files within bin directly from the Masi repository. That may be simpler in your scenario.

    See this answer for more on those 2 strategies.


    On the submodules path, declaring the submodule is only half the work. You still have to initialize your submodule the first time by

    git submodule git init
    

    You need then pull your submodules:

    git submodule foreach git pull
    

    and then update your submodule

    git submodule update
    

    See also this practical example with Git submodules, part I and Git submodules, part II.

    The .gitmodules file only stores the paths, but the commit version does get stored with the main project.
    I created a project on GitHub to demonstrate what happens. Specifically look at this commit, which adds the submodule, to see what’s going on:

    +Subproject commit 60be4b09f51d2560802ebd744893bb6f737ef57c
    

    这篇关于通过子模块显示Git中的外部代码依赖性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆