프로그램을 개발하다보면 소스에 대한 버전관리는 필수 이다. 오래된 CVS 사용이후 SVN을 사용했었고, 최근에는 Git을 사용하고 있는데. 사실 Git에 대한 얘기를 들은지는 오래됐었지만 실제 사용까지는 시간이 많이 걸렸었데
git은 다른 버전 관리 소프트웨어들과 다른 개념을 갖고 있는게 있다보니 이를 이해하는것이 귀찮았었다. 하지만 Git 이 좋다니 몇가지 명령만으로 사용하고는 있었는데 최근에 Git 를 일종의 파일시스템으로 이용해봐야 겠다는 생각이 있어. 이렇게 하기위해서 Git에 대한 깊숙한 이해가 필요하기에
좀더 상세 하게 알아보게 되었다.
그러다 보니 그간 불분명했던 Git에 대한 것이 좀더 명확해졌는데. 이를 정리해 볼까 한다. 여기서는 Git 의 Repository 구조를 알기위해서는 Gi에서 Tree라는 object를 정확히 이해 하고 있어야하는데 이해대한 이해를 위해 git 의 Low Level 명령어를 이용해 Git repository에 파일과 디렉토리를 추가하는 것을 해볼것이다.
준비환경은 git 을 실행할 수 있는 환경이면 어디든 상관없는데. 참고로 여기서는 Windows 에 msysgit(http://code.google.com/p/msysgit/) 을 설치했을때 생겨나는 bash 쉘 에서 실행했다.
아래 내용은 git 의 문서인 (정확히는 Pro Git이라는 책의 온라인 링크) http://git-scm.com/book/en/Git-Internals 경로의 내용을 내 나름대로 좀더 명확하게 다뤄봤다고나 하는 정도이다.
먼저 git init 명령으로 빈 git 디렉토리 생성하고 진행한다.
init 명령을 통해 git repository를 생성하고 나서 이하의 디렉토리를 살펴보면 다음과 같다.
$ find .git -type f .git/config .git/description .git/HEAD .git/hooks/applypatch-msg.sample .git/hooks/commit-msg.sample .git/hooks/post-commit.sample .git/hooks/post-receive.sample .git/hooks/post-update.sample .git/hooks/pre-applypatch.sample .git/hooks/pre-commit.sample .git/hooks/pre-push.sample .git/hooks/pre-rebase.sample .git/hooks/prepare-commit-msg.sample .git/hooks/update.sample .git/info/exclude |
$ echo 'test content' | git hash-object -w --stdin d670460b4b4aece5915caf5c68d12f560a9fe3e4 |
$ find .git/objects -type f .git/objects/d6/70460b4b4aece5915caf5c68d12f560a9fe3e4 |
$ echo 'test content 2' > second.txt |
$ git hash-object -w second.txt warning: LF will be replaced by CRLF in second.txt. The file will have its original line endings in your working directory. 031da66cfe6457d8fb541fa95e54e5b600576d41 |
$ find .git -type f .git/config .git/description .git/HEAD .git/hooks/applypatch-msg.sample .git/hooks/commit-msg.sample .git/hooks/post-commit.sample .git/hooks/post-receive.sample .git/hooks/post-update.sample .git/hooks/pre-applypatch.sample .git/hooks/pre-commit.sample .git/hooks/pre-push.sample .git/hooks/pre-rebase.sample .git/hooks/prepare-commit-msg.sample .git/hooks/update.sample .git/info/exclude .git/objects/03/1da66cfe6457d8fb541fa95e54e5b600576d41 .git/objects/d6/70460b4b4aece5915caf5c68d12f560a9fe3e4 |
$ git update-index --add --cacheinfo 10644 d670460b4b4aece5915caf5c68d12f560a9fe3e4 first.txt |
$ find .git -type f .git/config .git/description .git/HEAD .git/hooks/applypatch-msg.sample .git/hooks/commit-msg.sample .git/hooks/post-commit.sample .git/hooks/post-receive.sample .git/hooks/post-update.sample .git/hooks/pre-applypatch.sample .git/hooks/pre-commit.sample .git/hooks/pre-push.sample .git/hooks/pre-rebase.sample .git/hooks/prepare-commit-msg.sample .git/hooks/update.sample .git/index .git/info/exclude .git/objects/03/1da66cfe6457d8fb541fa95e54e5b600576d41 .git/objects/d6/70460b4b4aece5915caf5c68d12f560a9fe3e4 |
$ git write-tree 802e62ded81357dc7b0f74ed37f72bf245f88a4b |
$ find .git/objects -type f .git/objects/03/1da66cfe6457d8fb541fa95e54e5b600576d41 .git/objects/80/2e62ded81357dc7b0f74ed37f72bf245f88a4b .git/objects/d6/70460b4b4aece5915caf5c68d12f560a9fe3e4 |
$ git cat-file -p 802e62ded81357dc7b0f74ed37f72bf245f88a4b 100644 blob d670460b4b4aece5915caf5c68d12f560a9fe3e4 first.txt |
$ echo 'commit first' | git commit-tree 802e62 296f93c8cd0adbd687cbf73b0c8cef61e138e71e |
$ find .git/objects -type f .git/objects/03/1da66cfe6457d8fb541fa95e54e5b600576d41 .git/objects/29/6f93c8cd0adbd687cbf73b0c8cef61e138e71e .git/objects/80/2e62ded81357dc7b0f74ed37f72bf245f88a4b .git/objects/99/12b44e53af4bce15827526c1709f75bc7bb88a .git/objects/d6/70460b4b4aece5915caf5c68d12f560a9fe3e4 $ git cat-file -p 296f93c8cd0adbd687cbf73b0c8cef61e138e71e tree 802e62ded81357dc7b0f74ed37f72bf245f88a4b author user@somecomp.co.kr <user@somecomp.co.kr> 1395645128 +0900 committer commiter@somecomp.co.kr <commiter@somecomp.co.kr> 1395645128 +0900 commit first |
$ find .git/refs .git/refs .git/refs/heads .git/refs/tags |
$ echo "296f93c8cd0adbd687cbf73b0c8cef61e138e71e" > .git/refs/heads/master |
$ ls second.txt |
$ git checkout -f master Already on 'master' $ ls first.txt second.txt |
$ find .git/objects -type f .git/objects/03/1da66cfe6457d8fb541fa95e54e5b600576d41 .git/objects/29/6f93c8cd0adbd687cbf73b0c8cef61e138e71e .git/objects/80/2e62ded81357dc7b0f74ed37f72bf245f88a4b .git/objects/99/12b44e53af4bce15827526c1709f75bc7bb88a .git/objects/d6/70460b4b4aece5915caf5c68d12f560a9fe3e4 |
$ git update-index --add --cacheinfo 10644 031da66cfe6457d8fb541fa95e54e5b600576d41 mydir/echo_second.txt |
$ find .git/objects -type f .git/objects/03/1da66cfe6457d8fb541fa95e54e5b600576d41 .git/objects/29/6f93c8cd0adbd687cbf73b0c8cef61e138e71e .git/objects/80/2e62ded81357dc7b0f74ed37f72bf245f88a4b .git/objects/99/12b44e53af4bce15827526c1709f75bc7bb88a .git/objects/d6/70460b4b4aece5915caf5c68d12f560a9fe3e4 |
$ git write-tree adf331e74367e0a991c41b7918e14be8faf3189b |
$ git cat-file -p adf331e74367e0a991c41b7918e14be8faf3189b 100644 blob d670460b4b4aece5915caf5c68d12f560a9fe3e4 first.txt 040000 tree 1f6e6885b83dd560a9d6ea062a3e3a997b035855 mydir |
$ git cat-file -p 1f6e6885b83dd560a9d6ea062a3e3a997b035855 100644 blob 031da66cfe6457d8fb541fa95e54e5b600576d41 echo_second.txt |
$ find .git/objects -type f .git/objects/03/1da66cfe6457d8fb541fa95e54e5b600576d41 .git/objects/1f/6e6885b83dd560a9d6ea062a3e3a997b035855 .git/objects/29/6f93c8cd0adbd687cbf73b0c8cef61e138e71e .git/objects/80/2e62ded81357dc7b0f74ed37f72bf245f88a4b .git/objects/99/12b44e53af4bce15827526c1709f75bc7bb88a .git/objects/ad/f331e74367e0a991c41b7918e14be8faf3189b .git/objects/d6/70460b4b4aece5915caf5c68d12f560a9fe3e4 |
'PC/MAC > 강좌' 카테고리의 다른 글
윈도우10 이미지에 Virtio 드라이버 포함 (Windows Custom ISO with Virtio Driver) (2) | 2015.09.12 |
---|---|
소규모 네트워크를 위한 강좌 목록 정리 (공유서버, VPN , 백업) (0) | 2013.10.10 |
VPN의 활용.가상인터페이스 이해.- PPTP를 이용한 외부에서의 공유폴더 접속하기, VPN 공유기/윈도우 설정 방법 (2) | 2013.05.23 |
VPN(가상사설망) 이란 "가상전용선(터널링)"을 이용한 "가상전용망" 이다. VPN 필요성과 개념정리 (3) | 2013.05.12 |
#4 AjaxPlorer를 이용한 스마트폰/PC 모두 사용가능한 웹디스크(WebDisk) 서버 만들기 - 우분투 NAS 구축 강좌 시리즈 (14) | 2013.03.20 |