How does git submodules accommodate Baichuan

sumodules

git submodules test

1. Use scenarios

Submodules have a situation that we often encounter: a project in one job needs to include and use another project. Maybe it's a third-party library, or a library you developed independently for multiple parent projects.
Now here's the problem: You want to think of them as two separate projects, and at the same time you want to use another in one project.

Let's give an example. Suppose you are developing a website and creating Atom subscriptions. You decide to use a library instead of writing your own Atom generation code.
You may have to install CPAN or Ruby gem to include code in shared libraries, or copy the source code directly into your own projects.
If you include this library, it's difficult to customize it in any way, and even more difficult to deploy, because you have to make sure that every client contains the library.
If you copy the code into your own project, any custom changes you make will make it difficult to merge the upstream changes.

Git solves this problem through sub-modules. Submodules allow you to use one Git repository as a subdirectory of another Git repository.
It allows you to clone another repository into your own project while maintaining submission independence.

2.submodules add (git submodules add)

$ git submodule add https://github.com/holidaying/typescriptVue.git src/apps/typescriptVue
Cloning into 'E:/liudan/sumodules/src/apps/typescriptVue'...
remote: Enumerating objects: 57, done.
remote: Counting objects: 100% (57/57), done.
remote: Compressing objects: 100% (41/41), done.
remote: Total 57 (delta 7), reused 57 (delta 7), pack-reused 0
Unpacking objects: 100% (57/57), done.
warning: LF will be replaced by CRLF in .gitmodules.
The file will have its original line endings in your working directory.

Enter typescript Vue

You can execute your own pull push

3. Download the project that has been associated with submodules

Download the main project git clone

git submodule init -> git submodule update perhaps(git clone --recurse-submodules https://github.com/holidaying/typescriptVue.git)
$ git submodule init
Submodule 'src/apps/typescriptVue' (https://github.com/holidaying/typescriptVue.git) registered for path 'src/apps/typescriptVue'

ld289@DESKTOP-DU7527P MINGW64 /e/liudan/sumodules (master)
$ git submodule update
Cloning into 'E:/liudan/sumodules/src/apps/typescriptVue'...

4. Common commands

  • git submodule foreach pull traversal update sub-module
  • git config alias.spush 'push --recurse-submodules=on-demand'
  • git config alias.supdate 'submodule update --remote --merge'
  • git spush
  • git supdate
  • cat .gitmodules
  • Git submodule deinit < sub-module name > git RM -- cached < sub-module name >
  • Vi. gitmodules (manual deletion of connections)

    $ git supdate
       ld289@DESKTOP-DU7527P MINGW64 /e/liudan/sumodules (master)
       $ git spush
       fatal: AggregateException encountered.
       Username for 'https://github.com':
       
       ld289@DESKTOP-DU7527P MINGW64 /e/liudan/sumodules (master)
       $ git supdate
       remote: Enumerating objects: 4, done.
       remote: Counting objects: 100% (4/4), done.
       remote: Compressing objects: 100% (2/2), done.
       remote: Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
       Unpacking objects: 100% (3/3), done.
       From https://github.com/holidaying/typescriptVue
          66be908..a5f8bba  master     -> origin/master
       Updating 66be908..a5f8bba
       Fast-forward
        test | 1 +
        1 file changed, 1 insertion(+)
        create mode 100644 test
       Submodule path 'src/apps/typescriptVue': merged in 'a5f8bba35547cd54f859cc4d955691b6c5da5798'
    

Reference items: submodules

Keywords: Programming git github Ruby TypeScript

Added by ow-phil on Wed, 31 Jul 2019 14:22:07 +0300