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

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

问题描述

我有一个大项目(比方说A repo),它有一个来自B repo 的子文件夹.当我从 A repo

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.

我见过git-submodulegit-subtree:

在另一个 git 仓库中维护 Git 仓库

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

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

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

我想要的是,例如:

结构如下:

A/
--- a.py

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

当我改变 B/b.py .

  1. 如果我在路径 A/ 上,git add 可以检测到 B/b.py 改变了,gitpush 仅将其提交给 A 存储库.

  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 )

  • 如果我在路径 A/B/ 上,git add 只将 B/b.py 更改添加到 B repo, 和 git push 仅将其提交到 B 存储库.

  • 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/  )
    

  • 一旦我想在另一台机器上 snyc A 和 B,就去做

  • 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'
    

  • 换句话说,A 和 B 充当独立的存储库.

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

    但事实是,A repo 将 B repo 视为子模块:

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

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

    B 回购https://github.com/eromoe/test2

    如何强制 A repo 跟踪 A/ 下的所有文件,以及 B repo 跟踪 A/B/ 下的所有文件?我希望 A 和 B 作为一个独立的 repo ,没有任何其他配置.

    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.

    推荐答案

    您可以使用以下命令将 test2 repo 中的文件添加到 test repo,如下所示:

    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
    

    注意:

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

    git add test2/ 会将 test2 文件夹及其文件视为普通文件夹和测试 repo 文件(创建模式 100644).

    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 会将 test2 文件夹视为测试 repo 的子模块(创建模式 160000).

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

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

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