-
- MacBook Pro 2.6 GHz 6코어 Intel Core i7
# Makefile이 있는 gitt folder로 이동
$ cd gitt
$ make
gcc -Og gitt.c main.c hash.c list.c sha1.c blob_tree.c -lpthread -o gitt
# 생성된 실행파일 gitt을 관리하고자 하는 폴더로 옮겨서 사용
$ mv gitt [관리하고자 하는 폴더]/gitt
# 해당 폴더로 이동
$ cd [관리하고자 하는 폴더]
$ ./gitt [명령]
$ ./gitt add .
ERROR: 초기화된 gitt저장소가 아닙니다.
$ ./gitt init
빈 gitt 저장소로 초기화 하였습니다. (/Users/baeseonghyun/Desktop/gitt_test/.gitt)
$ ./gitt init
ERROR: 이미 git 저장소로 설정되어 있습니다.
-
add 실행 전 파일들 생성
$ echo helloworld > temp1.txt $ echo helloworld > temp2.txt $ echo helloworld2 > temp3.txt $ mkdir myfolder $ cp temp3.txt myfolder/temp4.txt $ ls gitt myfolder temp1.txt temp2.txt temp3.txt
-
특정 파일들을 staging area에 올림
$ ./gitt add temp1.txt temp2.txt
-
또는, 모든 파일을 staging area에 올림
$ ./gitt add .
-
staging area에 있는 파일들을 commit하고, commit message를 남김
$ ./gitt commit "first commit"
-
index 파일의 내용이 최근 커밋과 동일한 상태에서 다시 커밋 실행
$ ./gitt commit "second commit"
-
새로운 파일 만들고 staged area에 올린 이후 두 번째 커밋 실행
$ echo helloworld3 > temp4.txt $ ./gitt add temp4.txt $ ./gitt commit "second commit"
아래와 같이 master에 새로운 commit의 hash를 저장한 것을 확인할 수 있음
새로운 commit의 commit file에는 아래와 같이, tree에 대한 hash와, 이전 commit 정보(parent), commit msg가 저장되어 있는 것을 확인할 수 있음
tree hash를 통해 tree file을 찾아가 보면, 아래와 같이 해당 tree에 속한 blob 파일들과, tree file들의 정보가 저장되어 있는 것을 확인 할 수 있음
만약 checkout을 통해 현재 HEAD에서 브랜치가 아닌 특정 commit hash를 가리키고 있는 경우, HEAD파일에 새로운 commit의 commit hash를 덮어써 줌
-
현재 브랜치 조회
$ ./gitt branch # 현재 branch를 조회
-
새로운 브랜치 생성
$ ./gitt branch test # test branch 생성
-
결과를 확인하기 위해, checkout 실행 전 master와 test 브랜치에 차이 만들어 줌
$ echo helloworld4 > temp5.txt $ ./gitt add . $ ./gitt commit "master commit" # master branch는 새로 생성된 파일인 temp5.txt를 포함하고 있게 됨
-
다른 브랜치로 head를 이동
$ ./gitt checkout test # test 브랜치로 체크아웃
-
다른 commit hash로 head를 이동
$ ./gitt checkout f554c219a2153238d7287597d6d5b5a157289596 # 기존의 test branch에서, master branch가 가리키고 있던 commit의 hash값으로 checkout
-
다시 브랜치를 master 브랜치로 바꾸어줌
$ ./gitt checkout master current branch: master
- Working Directory와 Staged Area를 비교하여 상태를 출력
# 현재 상태는 위의 명령들을 순서대로 실행하여 HEAD가 maseter브랜치를 가리킴 # master 브랜치는 master commit을 가리키는 상태임 [WD = Working Directory] $ ./gitt status # WD와 Staging Area가 차이가 없기 때문에 아무것도 출력되지 않음 $ echo helloworld4 > temp6.txt # temp6.txt를 새로 생성하여 WD와 Staging Area의 차이를 만듦 $ ./gitt status # WD에 temp6.txt가 생성되었다고 출력될 것임 $ ./gitt add . # temp6.txt를 Staging Area로 넣어줌 $ ./gitt status # 이제 WD와 Staging Area가 차이가 없기 때문에 아무것도 출력되지 않음 $ rm temp6.txt # temp6.txt를 삭제하여 WD와 Staging Area의 차이를 만듦 $ ./gitt status # WD에 temp6.txt가 삭제되었다고 출력될 것임 $ echo helloworld6 > temp6.txt # 새로 temp6.txt(hellowrold6)를 생성하여 Staging Area의 temp6.txt(helloworld4)와 파일에 차이를 만듦 $ ./gitt status # WD에서 temp6.txt가 수정되었다고 출력될 것임
- 따옴표 처리가 가능한 argument parser