如何使外部存储库和嵌入式存储库作为通用/独立存储库工作? [英] How to make outer repository and embedded repository work as common/standalone repository?

查看:126
本文介绍了如何使外部存储库和嵌入式存储库作为通用/独立存储库工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大项目(比如 A repo ),并且它有一个来自 B repo 。当我从 A回购

 警告提交时,我会遇到下面的警告:添加嵌入式git存储库:extractor / annotator-server 
提示:您已经在当前存储库中添加了另一个git存储库。
提示:外部存储库的克隆将不包含
提示的内容:嵌入式存储库并且不知道如何获取它。
提示:如果您打算添加子模块,请使用:
hint:
hint:git submodule add< url>提取器/注释器 - 服务器
提示:
提示:如果您错误地添加了此路径,可以将其从
hint:index中删除:
hint:
提示:git rm --cached extractor / annotator-server
提示:
提示:有关更多信息,请参见git help submodule。

我已经看到 git-submodule git-subtree

在另一个git repo中维护Git repo $ b

https://www.atlassian.com/blog/git/alternatives-to-git-submodule-git

但我不喜欢它们,因为它们需要额外的配置。






我想要的是,例如:



结构如下:

  A / 
--- a.py

--- B /
--- B / b.py

当我更改 B / b.py


  1. 如果我在路径 A / git add 可以检测到 B / b.py 已更改, git push 到回购。

      git add。 (会在A /下添加更改)
    git push(会在A /下推送更改)
    git pull(会在A /下拉动更改)
    git克隆XXX:A(将克隆所有文件在A /下,A / B /只是看起来像所有文件的普通文件夹,而不是回购)


  2. 如果我的路径 A / B / git add 只加 B / b.py 对B repo的更改, git push 仅将其提交给B repo。

      git add。 (会在B /下添加更改,但不会将更改添加到A回购)
    git push(将B /下的更改推送,但不会将更改推送到A回购)
    git pull /)
    git clone XXX:B(将复制B /下的所有文件)


  3. 一旦我想在另一台机器上使用A和B,只要做到这一点:

      git clone A 
    rm - rf A / B /
    git克隆B ./B
    git add。 &安培;&安培; git commit'与B'同步


字,A和B作为独立回购。



但事实是,回购将B回购作为子模块:

回购
https://github.com/eromoe/test



B repo
https:// github。 com / eromoe / test2






如何强制回购追踪 A / 和B回购跟踪 A / B / 下的所有文件?我希望A和B充当自包含的repo,而不需要其他任何配置。

文件从test2回购测试回购如下:

 #在本地测试回购
rm -rf test2
git clone https://github.com/eromoe/test2
git add test2 /
git commit -am'从test2 repo添加文件到测试repo'
git push

注意:



您应该使用 git add test2 / (使用斜杠,而不是 git add test2 )。



git add test2 / 会处理 test2 文件夹,文件作为普通文件夹和文件进行测试回购(创建模式 100644 )。

git add test2 会将 test2 文件夹视为用于测试回购的子模块(创建模式 160000 )。


I have a big project(let's say A repo), and it there one child folder which is come from B repo. I would meet warning like below when I commit from A repo

warning: adding embedded git repository: extractor/annotator-server
hint: You've added another git repository inside your current repository.
hint: Clones of the outer repository will not contain the contents of
hint: the embedded repository and will not know how to obtain it.
hint: If you meant to add a submodule, use:
hint:
hint:   git submodule add <url> extractor/annotator-server
hint:
hint: If you added this path by mistake, you can remove it from the
hint: index with:
hint:
hint:   git rm --cached extractor/annotator-server
hint:
hint: See "git help submodule" for more information.

I have seen git-submodule and git-subtree:

Maintaining Git repo inside another git repo

https://www.atlassian.com/blog/git/alternatives-to-git-submodule-git-subtree

But I don't like them , because they need extra config.


What I want is , for example:

structure like:

A/
--- a.py

--- B/
--- B/b.py

When I change B/b.py .

  1. If I am on path A/ , git add can detect B/b.py changed, git push only commit that to A repo.

    git add .   (would add changes under A/  )
    git push   (would push changes under A/  )
    git pull   (would pull changes under A/  )
    git clone XXX:A  (would clone all files under A/ ,    A/B/ is just looks like plain folder with all files, not a repo )
    

  2. If I am on path A/B/ , git add only add B/b.py changes to B repo, and git push only commit that to B repo.

    git add .   (would add changes under B/ , but not add changes to A repo)
    git push   (would push changes under B/ , but not push changes to A repo)
    git pull   (would clone changes under B/ ,  )
    git clone XXX:B  (would clone all files under B/  )
    

  3. Once I want to snyc A and B in another machine, just do

    git clone A
    rm -rf A/B/
    git clone B ./B
    git add . && git commit 'sync with B'
    

In another word, A and B act as a standalone repo.

But the truth is , A repo treat B repo as submodule:

A repo https://github.com/eromoe/test

B repo https://github.com/eromoe/test2


How do I force A repo track all files under A/ , and B repo track all files under A/B/ ? I want A and B act as a self-contain repo , without any other config.

解决方案

You can use below commands to add files from test2 repo to test repo as below:

# In local test repo
rm -rf test2
git clone https://github.com/eromoe/test2
git add test2/
git commit -am 'add files from test2 repo to test repo'
git push

Note:

You should use git add test2/ (with slash, not git add test2).

git add test2/ will treat test2 folder and it's files as ordinary folder and file for test repo (create mode 100644).

git add test2 will treat test2 folder as a submodule for test repo (create mode 160000).

这篇关于如何使外部存储库和嵌入式存储库作为通用/独立存储库工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆