【问题标题】:git init in a git subdirectorygit 子目录中的 git init
【发布时间】:2013-02-27 12:44:44
【问题描述】:

我有一个 git repo,里面有一些子目录:

  ~/src
  ~/src/.git
  ~/src/mystuff
  ~/src/otherstuff

现在我想与朋友分享otherstuff,我打算用 bitbucket 来做这个。他们应该能够克隆它并在otherstuff 中推送更改,但我不希望他们能够访问srcmystuff(甚至看不到它们存在)。

我该怎么做?我几乎进入了cd ~/src/otherstuff 并做了git initgit remote add origin ssh://git@bitbucket.org/wim_glenn/...,但是当它已经在版本控制之下时,再次执行 git init 有什么不好的地方。

【问题讨论】:

  • 如何使用两个 repos,一个在另一个中的子模块?
  • 是的,怎么样?这是什么意思,我该怎么做等等。
  • 见这里:git submodule
  • 嗯,你的情况是在以一种非预期的方式使用 git。 :) 仅影响“mystuff”的修订,或影响同一提交中的“mystuff”和“otherstuff”的修订会发生什么?你不能只是把一个 git repo 撕成两半,然后期望它会很开心。子模块用于将外部存储库连接在一起,例如 svn:externals。
  • 这样的东西有用吗? stackoverflow.com/questions/1662753/… 或者你真的想把这个 repo 保存在一个部分,但仍然只共享那个子目录?

标签: git git-submodules git-subtree


【解决方案1】:

在 git 存储库中创建 git init 有效:您初始化 嵌套 存储库的目录会被父存储库忽略。

但是,如果该子目录的历史很重要,最好是export it as a separate repo(如Nicksuggested)。
从那里,您可以通过将新存储库声明为 a submodule of the parent repo 来保持两个存储库的锁定步骤。

【讨论】:

    猜你喜欢
    • 2015-05-08
    • 2018-02-21
    • 2013-06-03
    • 2014-01-12
    • 2013-02-18
    • 1970-01-01
    • 1970-01-01
    • 2021-04-13
    相关资源
    最近更新 更多