GIT submodule
본문 바로가기
GIT

GIT submodule

by bsp-martin 2021. 12. 24.

 

GIT submodule 이란

GIT 으로 사용중인 프로젝트의 아래 submodule GIT 으로 별도로 GIT 을 관리하고 싶을때 이용함

 

GIT TAG 에서 사용된 프로젝트를 Clone 하여 이번 submodule 을 진행해보도록 하겠다.

 

git clone git-tag/ git-submodule
cd git-submodule/
tree

 

프로젝트에서 sdk-submodule 이란 다른 프로젝트를 준비한다.

주의점은 submodule 로 사용할 sdk-submodule 프로젝트 역시 개별적 git 프로젝트여야한다.

따라서 git init / git add / git commit 상태여야한다. 아래를 참고해보자.

cd ~/prj/git
mkdir -p sdk-submodule/src
touch sdk-submodule/src/1.c sdk-submodule/src/2.c sdk-submodule/src/3.c
cd sdk-submodule
git init .
git add .
git commit -m "Init SDK submodule"
git log
tree

 

 

다음을 실행하여 sdk-submodule(서브모듈) 를 git-submodule (메인프로젝트)의 submodule 로 등록해보자.

문법:
git submodule add [Submodule URL]

git submodule add -b ../sdk-submodule/
git status .
git commit -m "submodule Added"

>> sdk-submodule(sub proj) 을 git-submodule(main proj) 하기에 추가한것

 

 

git-submodule 의 sdk-submodule 에서 새로운 파일을 생성후 루트에서 git status 를 확인해보면

echo "New text" > sdk-submodule/new_test.txt
git status .

위처럼 새로운 수정내역이 submodule 하기에 존재할때에는

sdk-submodule  에서 untracked content 가 있다고만 나오고 자세한 어떤파일 변경이 있는지는 관여하지 않는다.

 

sdk-submodule 에서 확인해보면

cd sdk-submodule
git status .

new_test.txt 라는 파일이 untracked files 로 구체적으로 나와있다.

 

 

이번에는 sdk-submodule 에서 commit 을 해보고 상위 git-submodule git 에서 상태를 확인해보자.

git add new_test.txt
git commit -m "[sdk] added new_test.txt"
cd ..
git status .

sdk-submodule 에서 (new commits) 새로운 commit 이 존재함을 나타낸다.

modified 로 된 내용이기 때문에 submodule 에 대해

git-submodule 에서도 이를 반영할수있다.

 

git add sdk-submodule/
git commit -m "updated submodule"

git log

 

git submodule 에대해

프로젝트에 submodule 을 추가하고 새로운 파일을 추가하는 방법에 대해 실습해보았다.

 

 

참고사이트:

https://git-scm.com/book/ko/v2/Git-%EB%8F%84%EA%B5%AC-%EC%84%9C%EB%B8%8C%EB%AA%A8%EB%93%88

 

 

 

반응형

'GIT' 카테고리의 다른 글

GIT format-patch  (0) 2021.12.24
GIT remote  (0) 2021.12.24
GIT TAG  (0) 2021.12.24

댓글