주 메뉴 열기

wwiki β

바뀜

Git

8,171 바이트 추가됨, 2024년 2월 27일 (화)
GIT_SSH
https://git-scm.com/
 
==config==
해당프로젝트에 설정내용을 확인하고 변경할 수 있다. # <code>/etc/gitconfig</code> : 시스템의 모든 사용자와 모든 저장소에 적용되는 설정이다. <code>git config --system</code> 옵션으로 이 파일을 읽고 쓸 수 있다.# <code>~/.gitconfig</code> : 현재 사용자. <code>git config --global</code># <code>.git/config</code> : 해당 폴더. <code>git config --local</code> 설정은 local>global>system 순으로 우선시 된다. 범위 지정이 없으면 local로 설정된다. 다음 명령을 사용하여 설정파일 위치를 확인할 수 있다. gitbash에서는 위의 경로를 사용할 수 있다. $ git config --list --show-origin === 사용자 정보(user) ===
$ git config user.name "[사용자명]
$ git config user.email "[이메일주소]"
전역적으로 설정하는 경우에 --global 을 추가하면 현재 사용자에 대해 설정된다. === 자격(credential) === $ git config --global credential.https://github.com<nowiki/>.provider generic<syntaxhighlight lang="ini">[credential "https://github.com"] provider = generic</syntaxhighlight><code>generic</code> 자격 증명 공급자는 플랫폼에 독립적인 방식으로 자격 증명을 저장하고 검색하는 데 사용됩니다. 그러나 <code>generic</code> 공급자의 구현은 특정한 공급자나 플랫폼에 따라 다릅니다.  윈도우에서 기본값은 <code>manager-core</code>인데, Windows Credential Manager를 사용하게 되는데, GUI가 포함되어 있으므로 스크립트를 사용하는 경우에 중단될 수 있다.  <code>store</code>는 디스크에 암호화하지 않고 저장하므로 권장되지 않는다.  == clone ==새로운 디렉토리에 다른 repository를 복제한다. --recurse-submodules 옵션을 붙이면 서브모듈을 자동으로 초기화하고 업데이트한다. == init ==clone과 함께 git저장소를 만든다.  이 명령은 .git 이라는 하위 디렉토리를 만든다. .git 디렉토리에는 저장소에 필요한 뼈대 파일(Skeleton)이 들어 있다. 이 명령만으로는 아직 프로젝트의 어떤 파일도 관리하지 않는다.  Git이 파일을 관리하게 하려면 저장소에 파일을 추가하고 커밋해야 한다. git add 명령으로 파일을 추가하고 git commit 명령으로 커밋한다:<syntaxhighlight lang="bash">$ git init$ git add *.c$ git commit</syntaxhighlight> == remote ==<syntaxhighlight lang="bash">$ git remote -vorigin https://github.com/schacon/ticgit (fetch)origin https://github.com/schacon/ticgit (push)</syntaxhighlight>git clone명령은 암시적으로 원격 저장소를 추가한다.명시적으로 하려면 다음과 같다.<syntaxhighlight lang="bash">$ git remote add <shortname> <url></syntaxhighlight>'origin'은 git이 복제한 서버에 부여하는 기본이름이다. == pull ==다른 repository 또는 로컬 브랜치에서 가져와서 통합한다. [[Git#fetch|fetch]]와 merge를 한번에 실행한 것과 같다. git init으로 로컬 저장소만 만든 후에 git remote add로 원격 저장소를 추가하여 트래킹 정보가 없는 경우에는 다음 명령을 사용할 수 있다. <syntaxhighlight lang="bash">$ git pull <remote> <branch></syntaxhighlight>일반적으로 <remote>는 "origin"이고, <branch>는 "master"이다. == checkout ==브랜치간에 전환하거나 작업 디렉토리를 복구한다. $ git checkout {브랜치명} == branch ==List, create, or delete branches If <code>--list</code> is given, or if there are no non-option arguments, existing branches are listed; ''git branch'' [--track[=(direct|inherit)] | --no-track] [-f] [--recurse-submodules] <branchname> [<start-point>] The command’s second form creates a new branch head named <branchname> which points to the current <code>HEAD</code>, or <start-point> if given.  === --delete === $ git branch --delete <branch-name> == fetch ==다른 repository로부터 최신 리비전을 다운 받는다. clone, pull은 fetch와 merge가 동시에 일어난다. 최신 리비전을 이름없는 브랜치로 가져온다.  이 브랜치를 '''FETCH_HEAD'''라는 이름으로 체크아웃할 수도 있다. FETCH_HEAD브랜치를 merge하거나 fetch하지 않고 [[Git#pull|pull]]하여 통합할 수 있다.  super-project-pointer라는 이력이 남는다. == merge ==둘 이상의 개발기록을 하나로 결합 == submodule ==서브모듈은 독립적인 저장소이다. 메인 프로젝트를 복제한 경우 각 서브모듈별로 업데이트해야 파일을 받는다. 서브모듈을 수정한 경우엔 master branch로 전환한 후 변경사항을 push한 후에 메인 프로젝트를 push해야한다. === Command ===With no arguments, shows the status of existing submodules. Several subcommands are available to perform operations on the submodules. ==== add ====<syntaxhighlight lang="bash">$ git submodule add https://github.com/myid/myproject.git</syntaxhighlight>메인모듈에 .gitmodules 이란 파일을 만들어 서브모듈의 정보를 저장한다.  서브모듈의 버전(해시)은 별도의 파일에 저장된다. 메인모듈을 새로 clone하는 경우 서브모듈은 clone되지 않는다. 추가명령으로 받아야 한다. ==== init ====먼저 git submodule init 명령을 실행하면 서브모듈 정보를 기반으로 로컬 환경설정 파일이 준비된다. 이후 git submodule update 명령으로 서브모듈의 리모트 저장소에서 데이터를 가져오고 서브모듈을 포함한 프로젝트의 현재 스냅샷에서 Checkout 해야 할 커밋 정보를 가져와서 서브모듈 프로젝트에 대한 Checkout을 한다.  간단하게 실행하는 방법도 있다. 메인 프로젝트를 clone할 때 [[Git#clone|git clone]] 명령 뒤에 --recurse-submodules 옵션을 붙이면 서브모듈을 자동으로 초기화하고 업데이트한다. ==== update ====원격 저장소에서 파일을 가져온다. 최신버전을 가지고 오는 것이 아니다. 메인모듈의 ''.git/modules/sub-module/HEAD''에 저장된 커밋 해시의 리비전을 가지고 온다.  --remote 옵션으로 최신버전을 가지고 온다. $ git submodule --remote--recursive 옵션으로 여러 서브모듈에 대해서 업데이트할 수 있다. $ git submodule update --remote --recursive브랜치를 가지지 않는다. 메인모듈을 clone한 후에 update --init명령으로 서브모듈을 다운로드할 수 있다.<syntaxhighlight lang="bash">$ git submodule update --init</syntaxhighlight> === deinit === $ git submodule deinit [모듈].git/modules와 소스폴더 삭제 $ rm -rf .git/modules/[모듈]  $ rm -rf [모듈] === 서브모듈의 버전 관리 ===master로 checkout하지 않고 서브모듈을 수정했다면 변경사항을 commit하고(HEAD의 hash가 변경됨) 다음 명령으로 임시 branch를 생성하되, <start-point>(f496c73)를 주어 변경사항을 유지한 채 새 브랜치를 생성한다. $ git [[Git#branch|branch]] <new-branch-name> f496c73<new-branch-name> 이름을 일시적으로 사용한다면 temp정도를 사용할 수 있다. master로 체크아웃한 후에 merge한다.<syntaxhighlight lang="bash">$ git checkout master$ git merge temp</syntaxhighlight>임시 브랜치를 삭제하려면 git [[Git#branch|branch]]명령을 사용할 수 있다. === 외부링크 ===https://git-scm.com/book/ko/v2/Git-도구-서브모듈 == Git Hooks ==https://git-scm.com/book/ko/v2/Git맞춤-Git-Hooks .git/hooks가 기본 디렉토리이다. === 훅 설치하기 ===실행만 할 수 있으면 된다. 실행할 수 있는 스크립트 파일을 확장자 없이 저장소의 hooks 디렉토리에 넣으면 스크립트가 켜진다. == Git 내부 == === 환경변수 === ==== 디버그 관련 변수 ==== ===== GIT_TRACE ===== * “true”, “1”, “2” – stderr 표준에러출력으로 Trace 로그를 출력함(1 이상 10 이하의 숫자는 해당 FD로 출력함). ==== 잡동사니 변수 ==== ===== GIT_SSH =====Git이 SSH 리모트로 연결할 때 <code>ssh</code> 명령 대신 설정된 명령을 사용한다. GIT_SSH_COMMAND="ssh -v"  혹은, [[SSH#ssh config|SSH 설정]]에서 변경할 수 있다.[[분류:명령어]][[분류:프로그래밍]]
편집
2,431