Git nâng cao
Amanda Crawford-Adamo
Software and Data Engineer
Git Submodule
git submodule

Thêm submodule bằng liên kết hoặc thư mục dưới đường dẫn chỉ định.
git submodule add <repository link|dir> <path>
$$
Ví dụ
Thêm thư viện data validator vào dự án ETL dưới thư mục libs/validator trong repo ETL.
git submodule add https://github.com/example/data-validator.git libs/validator
Liệt kê tất cả submodule trong dự án
git submodule status
Ví dụ
$ git submodule status
e1f2...7w8x9 data_cleaning_lib
a1b2...q7r8 api_connector
d9e8...t3u2 visualization_toolkit
Cập nhật submodule với thay đổi mới nhất
Có vài tùy chọn:
git submodule update --init
git submodule update --init --remote
git submodule update --init <path_to_submodule>
Quy trình xóa submodule
git submodule deinit <submodule_name>
git rm <path>
Sao chép mọi tệp cần có trong repo submodule mới sang một thư mục khác ngoài repo.
Trong thư mục mới, tạo repo mới cho submodule:
git init <new-submodule>
Dùng git filter-repo để trích xuất tệp và lịch sử liên quan từ dự án chính:
git filter-repo --path <extract_path> --invert-paths
Thêm repo đã trích xuất làm submodule vào dự án chính:
git submodule add <new-submodule_path> <path_to_store_submodule>
Trường hợp dùng:
Thực hành tốt:
Git nâng cao