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

查看:196
本文介绍了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 repo中维护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.

例如,我想要的是

结构类似:

A/
--- a.py

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

当我更改B/b.py时.

  1. 如果我在路径A/上,git add可以检测到B/b.py更改,则git push仅将其提交给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存储库中,而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/  )
    

  • 一旦我想在另一台计算机上对A和B进行Snyc操作,

  • 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回购将B回购视为子模块:

    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充当独立的仓库,而无需任何其他配置.

    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存储库添加到测试存储库,如下所示:

    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文件夹及其文件视为普通文件夹和用于测试存储库的文件(创建模式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文件夹视为测试存储库的子模块(创建模式160000).

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

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

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