git BitBucket - 创建存储库和子模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36327862/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 11:54:44  来源:igfitidea点击:

BitBucket - Create repository and sub modules

gitbitbucketgit-addbitbucket-server

提问by Jatin

I am using bitbucketweb interface and have created a new project "Test_Project". In this project, I am able to create a new repository - 'Module1' using Create repositoryoption.

我正在使用bitbucketWeb 界面并创建了一个新项目“Test_Project”。在这个项目中,我可以使用Create repository选项创建一个新的存储库 - 'Module1' 。

Now I want to create repository hierarchy in bitbucket project - Test_Project as following :-

现在我想在 bitbucket 项目中创建存储库层次结构 - Test_Project 如下:-

Test_Project (Bitbucket project)

Test_Project(Bitbucket 项目)

  • Web (Repository 1)

     Module1 (Sub-Repository/Sub-module 1)
     Module2 (Sub-Repository/Sub-module 2)
     Module3 (Sub-Repository/Sub-module 3)
    
  • Mobile (Repository 2)

     Module1 (Sub-Repository/Sub-module 1)
     Module2 (Sub-Repository/Sub-module 2)
     Module3 (Sub-Repository/Sub-module 3)
    
  • Archive (Repository 3)

     Module1 (Sub-Repository/Sub-module 1)
     Module2 (Sub-Repository/Sub-module 2)
     Module3 (Sub-Repository/Sub-module 3)
    
  • Project Documents (Repository 4)

    And so on..

  • 网络(存储库 1)

     Module1 (Sub-Repository/Sub-module 1)
     Module2 (Sub-Repository/Sub-module 2)
     Module3 (Sub-Repository/Sub-module 3)
    
  • 移动(存储库 2)

     Module1 (Sub-Repository/Sub-module 1)
     Module2 (Sub-Repository/Sub-module 2)
     Module3 (Sub-Repository/Sub-module 3)
    
  • 存档(存储库 3)

     Module1 (Sub-Repository/Sub-module 1)
     Module2 (Sub-Repository/Sub-module 2)
     Module3 (Sub-Repository/Sub-module 3)
    
  • 项目文件(存储库 4)

    等等..

So that I will add the local projects in respective bitbucket sub repositories

这样我就可以在各自的 bitbucket 子存储库中添加本地项目

Can anyone please guide how to create the sub-repositories/sub-modules in new repository in bitbucket.

任何人都可以指导如何在 bitbucket 的新存储库中创建子存储库/子模块。

采纳答案by Jatin

Now, I am able to create Bitbucket Repository Structure with sub-repository/sub-folders.

现在,我可以使用子存储库/子文件夹创建 Bitbucket 存储库结构。

Please follow these steps:-

请按照以下步骤操作:-

  1. Create a new Repository in Bitbucket project.
  2. To interact with your new repository, you'll need to clone this repository to your local machine using a git client. I am using ‘SourceTree' as a GIT client (another Atlassian product, integrates well with Bitbucket, you can use a "Clone To SourceTree" button in Bitbucket to make things easier).
  3. Once you have a local repository, copy/move your project into it , and use your chosen tool to add/commit the files and push them to bitbucket.
  1. 在 Bitbucket 项目中创建一个新的存储库。
  2. 要与新存储库交互,您需要使用 git 客户端将此存储库克隆到本地计算机。我使用“SourceTree”作为 GIT 客户端(另一个 Atlassian 产品,与 Bitbucket 集成良好,您可以使用 Bitbucket 中的“Clone To SourceTree”按钮使事情变得更容易)。
  3. 拥有本地存储库后,将您的项目复制/移动到其中,然后使用您选择的工具添加/提交文件并将它们推送到 bitbucket。

Thanks,

谢谢,

Jatin

贾廷

回答by CodeWizard

You simply need to be in your root folder and then add the submodule folder.

您只需要在根文件夹中,然后添加子模块文件夹。

git submodule add <url>

Now when you clone the project you simply need to init and update the submodule

现在,当您克隆项目时,您只需要初始化并更新子模块

git submodule init
git submodule update

Git 1.8.2 features a new option --remote

Git 1.8.2 提供了一个新选项 --remote

git submodule update --remote --merge

will fetch the latest changes from upstream in each submodule, merge them in, and check out the latest revision of the submodule. As the docsput it:

将从每个子模块的上游获取最新更改,将它们合并,并检查子模块的最新版本。正如文档所说:

--remote

This option is only valid for the update command. Instead of using the superproject's recorded SHA-1 to update the submodule, use the status of the submodule's remote-tracking branch.

--remote

此选项仅对更新命令有效。不要使用超级项目记录的 SHA-1 来更新子模块,而是使用子模块的远程跟踪分支的状态。

This is equivalent to running git pull in each submodule.

这相当于在每个子模块中运行 git pull 。



Git 2.8 update

Git 2.8 update

Parallel fetches of submodules

Using git submodules, one Git repository can include other Git repositories as subdirectories1. This can be a useful way to include libraries or other external dependencies into your main project. The top-level repository specifies which submodules it wants to include, and which version of each submodule.

When you fetch into the top-level repository, you typically want to fetch into the submodule repositories as well:

git fetch --recurse-submodules

If you have a lot of submodules, all of these fetches can be time-consuming; git fetch is essentially run in each submodule in turn.

But now you can speed things up by fetching from multiple submodules in parallel. For example,

git fetch --recurse-submodules --jobs=4

子模块的并行获取

使用git submodules,一个 Git 存储库可以包含其他 Git 存储库作为子目录1。这是将库或其他外部依赖项包含到主项目中的有用方法。顶级存储库指定要包含哪些子模块,以及每个子模块的版本。

当您获取顶级存储库时,您通常还想获取子模块存储库:

git fetch --recurse-submodules

如果您有很多子模块,则所有这些获取都可能非常耗时;git fetch 本质上是依次在每个子模块中运行。

但是现在您可以通过并行从多个子模块中获取来加快速度。例如,

git fetch --recurse-submodules --jobs=4