嵌套但相互通信的 Git 存储库

huangapple go评论63阅读模式
英文:

nested but communicating git repositories

问题

不要担心,我将为您提供代码部分的翻译,不包括问题、示例和思考部分。以下是代码部分的翻译:

让`upper`、`left`和`right`分别表示如下图所示的目录。

    upper
    ├── left
    └── right

请告诉我如果您需要任何进一步的翻译。

英文:

let upper, left, and right be directories as in the following diagram.

upper
├── left
└── right

question

how do i best manage these with git as local git repositories such that

  • each upper, left and right has a separate git repository,
  • histories from the repositories of left and right can be somehow propagated to the repository of upper,
  • histories from the repository upper can be somehow propagated to the repositories of left and right,

both of the latter preferably being done without changing the corresponding work-trees upper, left, and right?

example

for clarity, call the git repositories of upper, left and right just upper.git left.git and right.git respectively. (you can imagine them as bare repositories entirely outside the mentioned directory structure.) first

  • i work on left and commit to left.git; then
  • i somehow propagate the history from left.git to upper.git, so the latter knows about all the work i have done; then
  • i work on upper, sometimes working on files in right, and commit to upper.git; then
  • i somehow propagate the history from upper.git to right.git, so the latter knows about all the work i have done on files in right.

thoughts

initially i thought that i could realise this by using git subtree. but when i try to include the repository for left in upper using git subtree -P left add ⟨left.git⟩ master, i - perhaps unsurprisingly - get:

fatal: prefix 'left' already exists.

i have searched similar questions on stackoverflow, regarding nested repositories, but i quite don’t see how they relate to my problem. i probably don’t understand git subtrees well enough and perhaps i’m a bit too simple-minded in general. i have not looked deeply into git submodules; it seems to me that they are meant for something else.

答案1

得分: 1

不太清楚你对这样的结构有什么最终目标。如果你只打算将所有这些存储库保留在本地 - 没有必要使用子模块。

如果你想让上级存储库(而不是文件夹)包含来自内部存储库的所有更改(独立的提交树),你可以尝试查看这里的一些答案。

另一方面,我看不出有任何理由这样做。如果你只想保留不同存储库中文件夹的更改 - 创建独立的存储库,并将它们视为独立的。在这种情况下,upper.git 存储库(而不是文件夹)将忽略内部存储库的所有更改。每个内部存储库将跟踪自己的文件夹。

英文:

It's not quite clear what is your ultimate goal for such a structure.
If you only plan on keeping all these repos local - there is no need for submodules.

If you want upper repo (not folder) to contain all changes from inner repos (separate commit tree) you could try some answers from here.

On the other hand I don't see any reason to do so. If all you want is just keep changes of folders in different repositories - create independent repos, and treat them as such. In this case upper.git repo (not folder) will ignore all changes of inner repos. Each inner repo will keep track of it own folder.

huangapple
  • 本文由 发表于 2023年3月7日 21:45:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/75662785.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定