본격 초심자 대상, Git 빠른 설명서
Git Branch
Git는 하루에도 몇 번씩 쓰는 툴인데, 자세히 잘 모른다는게 오늘 갑자기 문득 생각이 나서 공부하게 됐다. 맨날 쓰는건 add, commit, push 밖에 없으니 그냥 단순 저장 용도로만 사용했었다. 검색해보니 commit tree 를 이쁘게 만들기 위한 rebase 란 것도 있고 다양하다. 자세히 알아보자.
우선 기본적으로 알아야할 사실은, git 에는 다음과 같이 5개의 영역이 있다는 것 자세한 내용은 아래 그림을 참조합시다!
– Workspace (Working Tree)
– Staging Area (Index)
– Local Branch
– Remote Tracking Branch ;; Refer to remote branch using fetch
– Remote Branch
그리고 HEAD 브랜치는, 현재 작업중인 브랜치를 가리키고, HEAD~1 은 그 이전, HEAD~2 는 HEAD~1 의 전 브랜치를 가리킨다. 그리고 HEAD^1 는 HEAD^ 와 동의어
Summary
시작 전에 본격 바쁘신 분들을 위한 서머리, 이것만 익히셔도..
– git diff : 워킹트리와 인덱스간 비교
– git diff --cached : 인덱스와 커밋(현재 브랜치)와 비교
– git reset HEAD : add(Staged) 를 취소, 다시 워킹 트리로 되돌림
– git reset --hard HEAD : 마지막 커밋 이후 모든 수정사항을 취소
– git reset HEAD^ : 마지막 커밋을 취소
– git commit --amend -m "message" : 마지막 커밋 메시지 변경
– git log --graph --decorate --oneline --branches --all : 커밋 리스트 이쁘게 출력
– git config --global alias.sl "log --decorate --graph --pretty=format:'%d %Cgreen%h%Creset (%ar - %Cred%an%Creset), %s'" : commit alias, git sl –all 처럼 사용
1. Workspace
git diff ;; workspace 와 staging srea(index) 간 차이점을 보여줍니다.
git diff HEAD ;; workspace 와 local branch : last commit 의 차이점을 보여줍니다.
2. Staging Area(index)
git reset HEAD ;; add 한 내용을 되돌립니다.
git reset --hard HEAD 모든 변경된 내용을 취소하고 마지막 커밋 상태로 복구합니다.
git diff --cached ;; Index 와 local branch : last commit 간 차이점을 보여줍니다.
3. Commit
git commit --amend ;; 편집기로 커밋 메세지를 수정할 수 있습니다.
git commit --amend -m "commit message"
git reset HEAD^ ;; 마지막 commit 을 취소합니다.
4. Commit History
git show HEAD ;; or master, whatever you want
git show --stat
git log
git log -p ;; shows the diff introduced it each commit
git log --stat ;; abbreviated stats
git log --pretty=oneline
git log --pretty=formatt:"%h - %an, %ar : %s"
git log --graph
git log --pretty=oneline --graph
옵션이 워낙 많다. 내 수준에서 기억해 둘만한건 두개정도인듯
– git log --pretty-oneline --graph
– git show HEAD
5. Branch
git branch new-one
git checkout new-one
git branch -d new-one
git branch ;; show a list of branches
git show-branch
6. Config
git config --global --list
References
- http://git-scm.com/book/ko/Git%EC%9D%98-%EA%B8%B0%EC%B4%88-%EC%BB%A4%EB%B0%8B-%ED%9E%88%EC%8A%A4%ED%86%A0%EB%A6%AC-%EC%A1%B0%ED%9A%8C%ED%95%98%EA%B8%B0
- http://yonoo88.tistory.com/204
- http://stackoverflow.com/questions/2221658/whats-the-difference-between-head-and-head-in-git
- http://blog.geekple.com/2012/09/19/git-alias/