Git:如何恢复替换子模块的符号链接提交?

时间:2016-07-26 12:45:10

标签: git symlink git-submodules

我的主存储库中有一个名为third-party的子模块。由于此模块太大,我在工作区中创建了一个符号链接到third-party文件夹。 令我不幸的是,我已将这个符号链接作为大胖合并的一部分进入我的分支!基本上,我已经用符号链接替换了一个子模块。

我试图删除链接和子模块更新,但没有帮助。

更多详情:

cat .gitmodules输出以下内容

[submodule "third-party"]
    path = third-party
    url = http://my-git-server/third-party.git

ls -la输出以下内容

drwxr-xr-x  3 user  admin  136 Jul 26 17:57 some-folder
drwxr-xr-x  3 user  admin  102 Jul 26 17:57 third-party -> /some/dead/path

我不知道如何从这种情况中恢复过来。任何帮助是极大的赞赏。

1 个答案:

答案 0 :(得分:1)

我尝试了多种方法,最后以下工作。更好的解决方法是受欢迎的!

#delete the symlink
rm third-party 

#delete the symlink from git 
git rm third-party

#remove the submodule
cat /dev/null>.gitmodules

#commit the changes
git add .
git commit -m "Removing third-party as submodule"

#add the submodule again
git add submodule http://my-git-server/third-party.git third-party

#get the latest code from the submodule
git submodule update --remote

这解决了我的问题。虽然现在第三方指向的提交哈希是不同的,但当我git submodule update --remote时,我会得到最新的代码!

相关问题