Skip to main content

Submodule usage

Let's create a token for adding submodule use. Otherwise, other people who do not have the permission cannot access to this repository during git clone the submodule stage.

YOLOv5 token : xY9cPG8QKudnZDwJ8

info

My goal is to add a submodule into the x64/PYD/ folder.

git submodule add http://gitremote-repo:xY9cPG8QKudnZDwJ8@10.1.20.11:5555/artificial-intelligence-team/yolov5.git x64/PYD/YOLOv5
git submodule init
git commit -m "update"
git push

Done!


The steps for pulling the submodule

git clone http://10.1.130.126:3000/AI-Team/test-submodule.git
git submodule update --init --recursive

Output:

$ git submodule update --init --recursive
Submodule 'x64/PYD/YOLOv5' (http://gitremote-repo:xY9cPG8QKudnZDwJ8@10.1.20.11:5555/artificial-intelligence-team/yolov5.git) registered for path 'x64/PYD/YOLOv5'
Cloning into 'x64/PYD/YOLOv5'...
Submodule path 'x64/PYD/YOLOv5': checked out '4678e05a8ad899c81fde485f3db7e35c344013'

Or

git clone --recursive http://10.1.130.126:3000/AI-Team/test-submodule.git

Output:

$ git clone --recursive http://10.1.130.126:3000/AI-Team/test-submodule.git
Cloning into 'test-submodule'...
remote: Counting objects: 12, done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 12 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (12/12), done.
Submodule 'x64/PYD/YOLOv5' (http://gitremote-repo:xY9cPG8QKudnZDwJ8@10.1.20.11:5555/artificial-intelligence-team/yolov5.git) registered for path 'x64/PYD/YOLOv5'
Cloning into 'test-submodule/x64/PYD/YOLOv5'...
remote: Enumerating objects: 6825, done.
remote: Counting objects: 100% (19/19), done.
remote: Compressing objects: 100% (19/19), done.
remote: Total 6825 (delta 7), reused 0 (delta 0), pack-reused 6806
Receiving objects: 100% (6825/6825), 24.77 MiB | 49.93 MiB/s, done.
Resolving deltas: 100% (4668/4668), done.
Submodule path 'x64/PYD/YOLOv5': checked out '4678e05a8ad899c81fde485f3db7e35c344013'

Whatever which way we used, we can see that it checked out to the specific commit node (i.e., 4678e05a).


After updated the submodule

After we updated the submodule, let's update the commit node of submodule to the latest one

Let's check the commit history.

Maintainer side

  1. Update the files in the submodule folder

    cd x64/PYD/YOLOv5
    git pull

    Output:

    remote: Enumerating objects: 3, done.
    remote: Counting objects: 100% (3/3), done.
    remote: Compressing objects: 100% (3/3), done.
    remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
    Unpacking objects: 100% (3/3), done.
    From http://10.1.20.11:5555//artificial-intelligence-team/yolov5
    4678e05..524c822 master -> origin/master
    Updating 4678e05..524c822
    Fast-forward
    README.md | 14 ++++++++------
    1 file changed, 8 insertions(+), 6 deletions(-)
  2. Check by git status that we can see it shows the new commits information, then let's add it to update the commit node of submodule.

    ## Let's go back to parent folder. Dont in the submodule folder.
    cd ..
    git status

    Output:

    $ git status                                                   
    On branch master
    Your branch is up to date with 'origin/master'.

    Changes not staged for commit:
    (use "git add <file>..." to update what will be committed)
    (use "git checkout -- <file>..." to discard changes in working directory)

    modified: YOLOv5 (new commits)

    no changes added to commit (use "git add" and/or "git commit -a")
  3. Let's add it.

    git add YOLOv5
    git commit -m "update YOLOv5 node commit"
    git push
  4. Let's check on your main repository (i.e., test-submodule). We can see that it updated the commit node of submodule.

    Then, you have done to update the submodule node.

Other users side

  1. Their commit node of submodule might be older, so our goal is to update the submodule commit progress. We can use git log to check it in the submodule folder.

    We can see the picture above that it showed the commit was at 4678e05a, not the latest one.

  2. Let's pull in the parent first to update the git history of main repository (i.e., not in the submodule). After do this action, it will update the submodule commit node to the latest one that maintainers updated it.

    $ git pull                                                          
    remote: Counting objects: 4, done.
    remote: Compressing objects: 100% (2/2), done.
    remote: Total 4 (delta 1), reused 0 (delta 0)
    Unpacking objects: 100% (4/4), done.
    From http://10.1.130.126:3000/AI-Team/test-submodule
    92f3610..e1229ac master -> origin/master
    Updating 92f3610..e1229ac
    Fast-forward
    x64/PYD/YOLOv5 | 2 +-
    1 file changed, 1 insertion(+), 1 deletion(-)
  3. Then let's update the submodule.

    $ git submodule update --init --recursive                         
    Submodule path 'x64/PYD/YOLOv5': checked out '524c822b4a7fbb74d0787b38c19150f4415cf700'

    Then we can see that now it updated to the commit node 524c822b

  4. Let's check the git log in the submodule folder.

    Done!

How to use the TortoiseGit to update?

reference: https://blog.yowko.com/git-submodule/


Miss the model | Git submodule update issue

When we use git submodule update --init --recursive to pull the submodule. It will not directly pull the latest commit from remote.

$ git submodule update --init --recursive                  
Submodule path 'chieh-submodule': checked out '829077e4ff77dbe58d61919360af674d347a1697'

Check from git status

$ git status                                                          
HEAD detached at 829077e
nothing to commit, working tree clean

It is not the latest commit node.

Hence, we can go to this folder, and git pull the latest progrsss from remote again.

$ git pull       

You are not currently on a branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

git pull <remote> <branch>

But we encounter this issue.

$ git pull origin chieh-submodule

From http://gitlab.com/chieh/chieh-submodule
* branch chieh-submodule -> FETCH_HEAD
Updating 829077e..33d9e7e
Checking out files: 100% (21/21), done.
Fast-forward
.gitignore | 2 +-
README.md | 5 +
test/main.py | 38 +-
test/requirements/Images/0_Image.png | Bin 0 -> 1104462 bytes
test/requirements/Images/1_Image.png | Bin 0 -> 1127364 bytes
test/requirements/Images/2_Image.png | Bin 0 -> 1098570 bytes
test/requirements/Images/3_Image.png | Bin 0 -> 1126494 bytes
test/requirements/Images/4_Image.png | Bin 0 -> 1121819 bytes
test/requirements/0_Image_0.jpg | Bin 0 -> 404725 bytes
test/requirements/1_Image_0.jpg | Bin 0 -> 407839 bytes
test/requirements/2_Image_0.jpg | Bin 0 -> 402468 bytes
test/requirements/3_Image_0.jpg | Bin 0 -> 406173 bytes
test/requirements/4_Image_0.jpg | Bin 0 -> 407555 bytes
test/utils.py | 18 +-
21 files changed, 92820 insertions(+), 24 deletions(-)
create mode 100644 test/requirements/Images/0_Image.png
create mode 100644 test/requirements/Images/1_Image.png
create mode 100644 test/requirements/0_Image_0.jpg
create mode 100644 test/requirements/1_Image_0.jpg
create mode 100644 test/requirements/2_Image_0.jpg
create mode 100644 test/requirements/3_Image_0.jpg
create mode 100644 test/requirements/4_Image_0.jpg

Successfully fetch the model from remote.