Skip to content

[Git] submodule로 중요한 정보 관리하기 #61

@backtony

Description

@backtony

https://tecoble.techcourse.co.kr/post/2021-07-31-git-submodule/

# submodule 등록
git submodule add {submodule_repository_url} {프로젝트에 어디로 가져올지 path}
git submodule add https://~~~/graphql-schema src/main/resources/graphql-schema

# 위 명령어를 사용하면 .gitmodules라는 파일이 생성됨
// 서비 모듈 이름
[submodule "hello"]
        // 현재 프로젝트 내에 서브 모듈이 위치할 경로
	path = src/main/hello
	// 서브모듈 url
	url = https://,,,~~~.git
	// 서브모듈에서 가져올 코드의 브랜치
	branch = master
// build.gradle.kts
val branchName = "master"

tasks.register("delete-hello-dir", Delete::class.java) {
    delete("src/main/hello")
}

// branch 이름 바꾸기
tasks.register("set-branch", Exec::class.java) {
    println("command : $branchName")
    commandLine("git", "submodule", "set-branch", "--branch", branchName, "src/main/hello")
    dependsOn("delete-hello-dir")
}

// submodules 가져오기
tasks.register("git-clone", Exec::class.java) {
    commandLine("git", "submodule", "update", "--remote", "--init")
    dependsOn("set-branch")
}
  • --init
    • 기존에 이미 초기화된 서브모듈은 추가적인 작업을 수행하지 않는다. 이전에 가져온 상태를 유지한다.
    • 새로운 서브모듈이 .gitmodules 파일에 추가되었거나 서브모듈을 처음 사용하는 경우, 해당 서브모듈은 초기화되어 로컬 프로젝트에 가져온다.
    • 즉, init은 서브모듈 초기화 작업을 수행하는 것으로 이미 초기화된 서브모듈에 대해서는 영향을 주지 않고 추가적인 작업없이 이전 상태를 유지한다.
  • update
    • 현재 서브모듈의 head 커밋을 사용하여 업데이트를 수행한다.
    • remote 옵션과 함께 사용시 서브모듈의 연결된 원격 저장소의 최신 커밋을 가져와 업데이트한다.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions