Git - 将更改从子模块推送到主模块?
Git - Pushing changes to master from a submodule?
我有两个 git 存储库,A
和 B
A
是其他项目喜欢使用的库。它只有一个分支 master
.
在 B
中,我将 A
添加为子模块,因此它会将其克隆到 B
的目录中。 HEAD
未分离,因为我说过在添加时跟踪分支 master
。
在我的项目 B
中,我注意到 A
的代码中存在错误。我更改了子模块 A
中的代码(位于 B
目录中的克隆代码)。我现在想提交我在 B
中对 A
所做的那些更改,将它们提交到 A
的主分支,而 B
仍然是零提交。
如何做到这一点?
例如
Projects
|---A # Existing repository. On branch master.
|---B # Repository just created.
git init
git submodule add -b master ../A
git submodule update --remote
cd A/
vi importantFile.txt # Here I make changes to internal files in A
# How do I now commit those changes and add a commit to A?
您只需在子模块的文件夹中执行git命令,它就会应用于子模块。你只需要确保那里的主人是最新的并且你没有处于分离头模式。
但是为了更新主项目的子模块(所以如果其他人用子模块检出主项目,到更新的版本)你肯定需要在那里提交来修改版本。
进一步阅读:Git commit to common submodule (master branch)
我有两个 git 存储库,A
和 B
A
是其他项目喜欢使用的库。它只有一个分支 master
.
在 B
中,我将 A
添加为子模块,因此它会将其克隆到 B
的目录中。 HEAD
未分离,因为我说过在添加时跟踪分支 master
。
在我的项目 B
中,我注意到 A
的代码中存在错误。我更改了子模块 A
中的代码(位于 B
目录中的克隆代码)。我现在想提交我在 B
中对 A
所做的那些更改,将它们提交到 A
的主分支,而 B
仍然是零提交。
如何做到这一点?
例如
Projects
|---A # Existing repository. On branch master.
|---B # Repository just created.
git init
git submodule add -b master ../A
git submodule update --remote
cd A/
vi importantFile.txt # Here I make changes to internal files in A
# How do I now commit those changes and add a commit to A?
您只需在子模块的文件夹中执行git命令,它就会应用于子模块。你只需要确保那里的主人是最新的并且你没有处于分离头模式。
但是为了更新主项目的子模块(所以如果其他人用子模块检出主项目,到更新的版本)你肯定需要在那里提交来修改版本。
进一步阅读:Git commit to common submodule (master branch)