git cheat sheet1
이 포스트는 여러 절로 구성되어 있습니다.
git에 대한 자세한 내용은 다음 책을 참고 바란다.
본 포스트에서는 git 기본 명령어와 옵션 별 기능을 정리하였다.
1. Setup
git init: 저장소(repository) 생성git clone [원격 저장소 url]: 해당 주소의 내용을 복제하여 저장소 생성git config user.name [작성자 이름]: 작성자 이름 설정git config user.email [이메일 계정]: 작성자 이메일 설정git config --list: 저장소 설정 전체 출력git config --get [설정항목]: 일부 설정항목만 출력(ex : git config –get user.name)git help [커맨드 이름]: 도움말
2. Stage & commit

git add [파일이름]: 수정된 파일을 staging area 올리기git add [디렉토리 명]: 해당 디렉토리 내에 수정된 모든 파일들을 staging area에 올리기git add .: working directory 내에 수정된 모든 파일들을 staging area에 올리기 (untracked 파일 제외)git commit: 이력 저장(commit)git commit -m "[메시지]": vim을 사용하지 않고 인라인으로 메시지를 추가하여 commitgit commit -am "[메시지]": add와 commit을 일괄적으로 진행
3. Inspect
git status
git status: 저장소 파일의 상태정보 출력git status -s: 파일 상태정보를 간략하게 표시
git log
git log: 저장소의 commit이력을 출력git log --pretty=oneline: 각 commit을 한줄로 출력(–pretty 옵션 사용)git log --oneline: 각 commit을 한줄로 출력git log --decorate=full: 브랜치나 태그정보를 상세히 출력git log --graph: 그래프 형태로 출력
git show
git show: 가장 최근의 commit 정보 출력git show [commit hash]: 해당 commit의 정보 출력git show HEAD: HEAD가 참조하는 commit의 정보 출력git show HEAD^^^: HEAD를 기준으로 3단계 이전의 commit정보 출력git show HEAD~[n]: HEAD를 기준으로 n단계 이전의 commit정보 출력
git diff
git diff: 최근 commit과 변경사항이 발생한(Unstaged) 파일들의 내용비교git diff --staged: 최근 commit과 Staging area의 파일들 간의 변경사항 출력git diff [commit hash1] [commit hash2]: 두 commit의 파일들 간의 변경사항 출력