용어 | 깃 서브모듈 git Submodule

|

요약

Git 저장소 안에 다른 Git 저장소를 디렉토리로 분리해 넣는 것이 서브모듈입니다.

Git – 서브모듈 (git-scm.com)

깃 서브모듈은 메인 레포지토리에 하위 레포지토리를 두고 관리하기 위한 구조입니다.
하나의 프로젝트에서 다른 프로젝트함께 사용해야 할 때 사용됩니다.

다른 독립된 Git 저장소를 Clone 해서 내 Git 저장소 안에 포함할 수 있으며 각 저장소의 커밋은 독립적으로 관리할 수 있습니다.

사례

중요 정보(비밀 키) 를 외부에 노출되지 않게 작업

사례자는 Jasypt 로 암호화를 할까 생각했습니다. 그러나 프로덕션 코드에 암호화를 위한 코드를 추가해야 하는 부담이 있어 깃 서브모듈을 선택했습니다.

사용법

git submodule add https://github.com/rit245/markdown

git submodule add 뒤에 추가할 저장소의 URL을 붙여줍니다. 지금까지 했던 프로젝트를 넣습니다.

상태 확인하기

git status 를 입력하면 현재 상태를 확인할 수 있습니다.

C:\Users\MAIN\Documents\github\220824_submodule>git status
On branch main
Your branch is up to date with 'origin/main'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        new file:   .gitmodules
        new file:   markdown

모든 서브모듈 업데이트하기

git submodule update --remote

비교하기

git diff

에러시 직접 머지하기

$ cd DbConnector

$ git rev-parse HEAD
eb41d764bccf88be77aced643c13a7fa86714135

$ git branch try-merge c771610
(DbConnector) $ git merge try-merge
Auto-merging src/main.c
CONFLICT (content): Merge conflict in src/main.c
Recorded preimage for 'src/main.c'
Automatic merge failed; fix conflicts and then commit the result.

foreach 명령어

$ git submodule foreach 'git stash'
Entering 'CryptoLibrary'
No local changes to save
Entering 'DbConnector'
Saved working directory and index state WIP on stable: 82d2ad3 Merge from origin/stable
HEAD is now at 82d2ad3 Merge from origin/stable

foreach 명령어를 통해 모든 서브메뉴를 일괄처리할 수 있습니다.

새로운 기능을 추가하거나 버그 수정을 해야하는 경우 위의 방법을 통해 Stash 명령을 실행할 수 있습니다.

  • stash : 현재 작업을 일시적으로 저장

새 브랜치로 이동하여 작업하기

$ git submodule foreach 'git checkout -b featureA'
Entering 'CryptoLibrary'
Switched to a new branch 'featureA'
Entering 'DbConnector'
Switched to a new branch 'featureA'

전체 diff 내용 보기

$ git diff; git submodule foreach 'git diff'
Submodule DbConnector contains modified content
diff --git a/src/main.c b/src/main.c
index 210f1ae..1f0acdc 100644
--- a/src/main.c
+++ b/src/main.c
@@ -245,6 +245,8 @@ static int handle_alias(int *argcp, const char ***argv)

      commit_pager_choice();

+     url = url_decode(url_orig);
+
      /* build alias_argv */
      alias_argv = xmalloc(sizeof(*alias_argv) * (argc + 1));
      alias_argv[0] = alias_string + 1;
Entering 'DbConnector'
diff --git a/src/db.c b/src/db.c
index 1aaefb6..5297645 100644
--- a/src/db.c
+++ b/src/db.c
@@ -93,6 +93,11 @@ char *url_decode_mem(const char *url, int len)
        return url_decode_internal(&url, len, NULL, &out, 0);
 }

+char *url_decode(const char *url)
+{
+       return url_decode_mem(url, strlen(url));
+}
+
 char *url_decode_parameter_name(const char **query)
 {
        struct strbuf out = STRBUF_INIT;

유용한 Alias

$ git config alias.sdiff '!'"git diff && git submodule foreach 'git diff'"
$ git config alias.spush 'push --recurse-submodules=on-demand'
$ git config alias.supdate 'submodule update --remote --merge'

서브모듈을 이용하는 명령은 대부분 길이가 길기 때문에 Alias 로 만들어 사용하는 것이 좋습니다.

용어

  • 업스트림(upstream) : 클라이언트(로컬 기기)에서 서버(원격호스트)로 보내지는 데이터를 이야기합니다.
  • 백본(backbone) : 여러 소형 네트워크들을 묶어 대규모 파이프라인을 통해 극도로 높은 대역폭으로 다른 네트워크들의 집합과 연결되는 네트워크(대규모 패킷 통신망) #나무위키

참조

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다