git将子模块添加到现有目录中

时间:2017-02-07 17:46:53

标签: git clone git-submodules git-clone

我在父文件夹中有一个git存储库。让我们称这个文件夹为“root”。 然后文件夹中有一个子目录,我们称之为“子”。我想要做的是将远程存储库作为子模块克隆到“child”中:

git submodule add git@github.com:username/repopath child/
git submodule add git@github.com:username/repopath ./child/

上述两个都给我错误:

  

子元素已存在于索引

我尝试删除被跟踪的目录:

git rm --cached .\child\*
git submodule add git@github.com:username/repopath child/

然后我收到这个错误:

  

'child'已经存在,并且不是有效的git repo

非常感谢任何帮助

由于

1 个答案:

答案 0 :(得分:1)

首先,在新克隆中尝试使用submodule add命令,因为之前的尝试可能会留下子模块的部分状态。

其次,先试试

git submodule add -- git@github.com:username/repopath child

然后,添加并提交。

最后,试试你的git submodule command

try {           
        // See comments on 
        //   https://developers.google.com/resources/api-libraries/documentation/translate/v2/java/latest/
        // on options to set
        Translate t = new Translate.Builder(
                new com.google.api.client.http.javanet.NetHttpTransport(), com.google.api.client.json.gson.GsonFactory.getDefaultInstance(), null)                                   
                //Need to update this to your App-Name
                .setApplicationName("Stackoverflow-Example")                    
                .build();           
        Translate.Translations.List list = t.new Translations().list(
                Arrays.asList(
                        //Pass in list of strings to be translated
                        "Hello World",
                        "How to use Google Translate from Java"), 
                    //Target language   
                    "ES");  
        //Set your API-Key from https://console.developers.google.com/
        list.setKey("you-need-your-own-api-key");
        TranslationsListResponse response = list.execute();
        for(TranslationsResource tr : response.getTranslations()) {
            System.out.println(tr.getTranslatedText());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

添加并提交。

相关问题