将子模块git更改为服务器

时间:2016-01-08 19:01:42

标签: git version-control bitbucket

我有一个团队git repo,它有一个子模块。我不得不进入子模块并进行更改。我将我的仓库推送到远程服务器。我对子模块所做的更改未显示在服务器上。只有非子模块发生变化。

我的同事也对子模块进行了更改。推动了变化,也没有出现。是否有特定的方法将更改推送到子模块?子模块是它自己的存储库,位于服务器上。

1 个答案:

答案 0 :(得分:1)

在子模块文件夹中进行更改时,需要直接在该文件夹中提交并推送。当推送子模块提交时,您需要转到父文件夹,然后进行额外的提交,并更改对子模块的引用,然后推送该提交。

以下是一个例子:

# current folder is parent project

cd submodule-git
# making changes in submodule 
touch new-file
git add new-file
git commit -m "new file was added"
git push origin master

cd ..
# changing reference to new commit in the parent project
git add submodule-git
git commit -m "updated submodule"
git push origin master

有时您无法使用子模块的默认远程URL来推送更改。例如,如果您使用只读URL,则可以仅在子模块中添加其他远程并使用它而不是原点。这是一个例子:

# current folder is parent project

cd submodule-git
# adding new remote with name 'write-origin' and ssh://user@example.com/project.git
git remote add write-origin ssh://user@example.com/project.git
# making changes in submodule and creating new commit 
git push write-origin master
相关问题