Recommanded Free YOUTUBE Lecture: <% selectedImage[1] %>

Contents

Git Cheat Sheet

https://lh6.googleusercontent.com/-2MNzVkNpZpk/Uc-SoMqCisI/AAAAAAAADKI/YPFKqK0VJ0A/s1024/git-cheat-sheet-medium.png

Cheat Sheet tutorial

Cheat sheet가 잘 정리돼 있기는 한데, 역시 몸을 직접 굴려가면서 배워야지 내 것이 되겠지. Git server를 새로 구축하기가 귀찮아서, github로 테스트 했다. 언젠가 시간되면 git server로 제대로 구축해봐야 겠다.

git과 github

SVN을 쓰다가 처음 git을 접했을 때 일이다. 분명히 git으로 소스코드를 관리한다고 들었는데, git server도 아니고 계속 github 이야기를 하는 거다. github가 뭐지 ? git server 프로그램의 (이를테면 기능을 추가한)일종인가. ? git 저장소를 관리기 위한 어떤 시스템인가 ?

SVN을 사용할 때는 github와 같은 그런 서비스가 없었기 때문에, 더 헛갈릴 수 밖에 없었다. 나중에야 git을 호스팅하는 서비스중 가장 성공한 서비스라는 걸 알게 됐다.

아마 git에 처음 발을 들여 놓는 많은 사람들이 나와 같은 경험을 할 거다.

테스트 환경

github에 테스트 환경을 꾸미기로 했다. Git server를 직접 구축하는 노가다가 싫었기 때문이다. 테스트를 위해서 gitsample이라는 이름의 프로젝트를 하나 만들었다. 이 프로젝트에는 README.md 파일이 하나 들어 있다.

이미 있는 저장소로 부터 만들기

git 저장소를 로컬 컴퓨터에 복사한다. git은 "https, git, ssh"를 이용해서 접근할 수 있다. github는 https와 git을 이용한 접근을 허용한다.
# git clone https://github.com/yundream/gitsample.git
# git clone git@github.com:yundream/gitsample.git 
# git clone ssh://you@host.org/proj.git

# git clone git@github.com:yundream/gitsample.git
Cloning into 'gitsample'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), 222 bytes, done.

정보 보기

git status

파일의 변경 정보를 보여준다.
$ git status 
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#   (use "git push" to publish your local commits)
#
master 브랜치에 하나의 commit이 있음을 알 수 있다.

git log

파일의 (diff)변경내역을 보여준다. 언제, 누가, 어떤 파일을 수정했는지를 확인할 수 있다.
# git log
commit ab51e3612bc41c467f4f9879dae9e1a218fa3ece
Author: yundream <yundream@gmail.com>
Date:   Sun Jun 30 23:16:59 2013 +0900

    테스트 문자열 추가

commit c3563b1b3f1ce44daf7df037fb76efee7e12396a
Author: yundream <yundream@gmail.com>
Date:   Sun Jun 30 23:16:00 2013 +0900

    프로젝트의 목표 추가

commit 9debbe30993e6ab88572d6aa85665a971e9ae94c
Author: yundream <yundream@gmail.com>
Date:   Sun Jun 30 07:02:47 2013 -0700

git diff

파일의 변경 내용을 추적한다. git log의 commit id를 이용해서 추적할 수 있다.
# git diff c3563b1b3f1ce44daf7df037fb76efee7e12396a
diff --git a/README.md b/README.md
index c9710d1..75a1f81 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,4 @@
 gitsample
 =========
 1. git cheat sheet에 있는 내용을 테스트하기 위한 테스트 프로젝트  
+1. Test 

id와 id를 특정해서 추적할 수도 있다.
$ git diff ab51e3612bc41c467f4f9879dae9e1a218fa3ece 9debbe30993e6ab88572d6aa85665a971e9ae94c   
diff --git a/README.md b/README.md                                                    
index 75a1f81..082fd07 100644                                                         
--- a/README.md                                                                       
+++ b/README.md                                                                       
@@ -1,4 +1,2 @@                                                                       
 gitsample
 =========
-1. git cheat sheet에 있는 내용을 테스트하기 위한 테스트 프로젝트  
-1. Test 

git blame

선택한 파일의 변경정보를 보여준다.
^9debbe3 (yundream 2013-06-30 07:02:47 -0700 1) gitsample
^9debbe3 (yundream 2013-06-30 07:02:47 -0700 2) =========
c3563b1b (yundream 2013-06-30 23:16:00 +0900 3) 1. git cheat sheet에 있는 내용을 테스
ab51e361 (yundream 2013-06-30 23:16:59 +0900 4) 1. Test 

git show

commit id의 원문을 보여준다. 예컨데, commit id를 이용해서 원문을 복원하는 목적으로 사용할 수 있다.
git show ab51e361:README.md
gitsample
=========
1. git cheat sheet에 있는 내용을 테스트하기 위한 테스트 프로젝트  
1. Test 

브랜치

$ git branch
* master

복원

Update

Publish

참고

  1. http://dogfeet.github.io/articles/2012/how-to-github.html
  2. http://zrusin.blogspot.kr/2007/09/git-cheat-sheet.html