【问题标题】:add modified git submodule which is not owned添加修改过的不属于自己的 git 子模块
【发布时间】:2020-02-29 19:15:31
【问题描述】:

是否可以添加您在本地修改但您不是其所有者因此无法推送到远程的 git 子模块。 目前我的 repo 只添加了一个指向原始子模块的链接,但没有我对它的修改。 但我希望将包括我的修改在内的全部内容推送到我的远程仓库。

到目前为止,我做了以下事情:

cd my_repo
git submodule add git@mygithost:submodulue submodule
git submodule init && git submodule update
cd submodule
<changes, hacks>
git commit -am 'modify submodule'
cd .. && git status

> On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)
  (commit or discard the untracked or modified content in submodules)

    modified:   submodule (untracked content)

no changes added to commit (use "git add" and/or "git commit -a")

【问题讨论】:

    标签: git git-submodules git-subrepo


    【解决方案1】:

    我希望将包括我的修改在内的全部内容推送到我的远程仓库。

    您不能完全这样做,因为您无法将本地更改推送到原始子模块。但是你可以通过分叉子模块来解决这个问题。

    首先,将git@submodulehost:submodulue 分叉到git@mygithost:submodulue。如果您不能直接在submodulehost 克隆并推送它:创建一个新的空存储库git@mygithost:submodulue 并执行

    git clone -o upstream git@submodulehost:submodulue
    cd submodule
    git remote add origin git@mygithost:submodulue
    git push --all origin
    

    然后使用 fork 作为子模块的源:

    cd ../superproject/submodule
    git remote set-url origin git@mygithost:submodulue
    git remote add upstream git@submodulehost:submodulue
    

    修复代码并将其推送到您的 fork:

    git push -u origin master
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-07-23
      • 1970-01-01
      • 2014-11-20
      • 2012-05-24
      • 2019-06-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多