Git命令速查

按类别整理的Git命令速查表。

82개 명령어

설정

命令说明
git config --global user.name "이름"
전역 사용자 이름 설정
git config --global user.email "이메일"
전역 이메일 설정
git config --list
설정 목록 확인
git config --global core.editor "code --wait"
기본 에디터 변경

저장소 생성 & 복제

命令说明
git init
새 Git 저장소 초기화
git clone <url>
원격 저장소 복제
git clone --depth 1 <url>
최신 커밋만 얕은 복제
git clone -b <branch> <url>
특정 브랜치만 복제

스테이징 & 커밋

命令说明
git status
현재 상태 확인
git add <file>
특정 파일 스테이징
git add .
모든 변경사항 스테이징
git add -p
변경사항을 부분적으로 스테이징
git commit -m "메시지"
커밋 생성
git commit --amend
마지막 커밋 수정
git commit --amend --no-edit
메시지 변경 없이 마지막 커밋 수정

브랜치

命令说明
git branch
로컬 브랜치 목록
git branch -a
모든 브랜치 목록 (원격 포함)
git branch <name>
새 브랜치 생성
git checkout <branch>
브랜치 전환
git checkout -b <branch>
브랜치 생성 후 전환
git switch <branch>
브랜치 전환 (Git 2.23+)
git switch -c <branch>
브랜치 생성 후 전환 (Git 2.23+)
git branch -d <branch>
브랜치 삭제 (머지된 경우)
git branch -D <branch>
브랜치 강제 삭제
git branch -m <old> <new>
브랜치 이름 변경

머지 & 리베이스

命令说明
git merge <branch>
브랜치 머지
git merge --no-ff <branch>
머지 커밋 강제 생성
git merge --squash <branch>
모든 커밋을 하나로 합쳐 머지
git merge --abort
머지 중단
git rebase <branch>
현재 브랜치를 대상 브랜치 위에 리베이스
git rebase -i HEAD~3
최근 3개 커밋 인터랙티브 리베이스
git rebase --abort
리베이스 중단
git rebase --continue
충돌 해결 후 리베이스 계속
git cherry-pick <commit>
특정 커밋만 현재 브랜치에 적용

원격 저장소

命令说明
git remote -v
원격 저장소 목록
git remote add origin <url>
원격 저장소 추가
git remote set-url origin <url>
원격 URL 변경
git push -u origin <branch>
브랜치 푸시 (업스트림 설정)
git push
현재 브랜치 푸시
git push origin --delete <branch>
원격 브랜치 삭제
git pull
원격 변경사항 가져오기 + 머지
git pull --rebase
원격 변경사항 가져오기 + 리베이스
git fetch
원격 변경사항 가져오기 (머지 안함)
git fetch --prune
삭제된 원격 브랜치 정리
git push --force-with-lease
안전한 강제 푸시

Stash

命令说明
git stash
현재 변경사항 임시 저장
git stash -u
추적되지 않는 파일 포함 임시 저장
git stash save "메시지"
메시지와 함께 임시 저장
git stash list
스태시 목록
git stash pop
최근 스태시 적용 후 삭제
git stash apply
최근 스태시 적용 (삭제 안함)
git stash apply stash@{2}
특정 스태시 적용
git stash drop
최근 스태시 삭제
git stash clear
모든 스태시 삭제

조회 & 로그

命令说明
git log --oneline
간략한 커밋 로그
git log --graph --oneline --all
모든 브랜치 그래프로 보기
git log -p <file>
파일의 변경 이력
git log --since="2024-01-01"
특정 날짜 이후 커밋
git log --author="이름"
특정 작성자의 커밋
git diff
스테이징되지 않은 변경사항
git diff --staged
스테이징된 변경사항
git diff <branch1>..<branch2>
두 브랜치 비교
git show <commit>
특정 커밋의 상세 정보
git blame <file>
파일의 각 줄 작성자 확인
git shortlog -sn
작성자별 커밋 수 통계
git reflog
HEAD 이동 이력 (복구용)

되돌리기

命令说明
git checkout -- <file>
파일의 변경사항 되돌리기
git restore <file>
파일 복원 (Git 2.23+)
git restore --staged <file>
스테이징 취소
git reset HEAD~1
마지막 커밋 취소 (변경사항 유지)
git reset --soft HEAD~1
커밋 취소 (스테이징 유지)
git reset --hard HEAD~1
마지막 커밋 취소 (변경사항 삭제)
git revert <commit>
특정 커밋을 되돌리는 새 커밋 생성
git clean -fd
추적되지 않는 파일/디렉토리 삭제
git clean -fdn
삭제될 파일 미리보기 (dry-run)

태그

命令说明
git tag
태그 목록
git tag v1.0.0
경량 태그 생성
git tag -a v1.0.0 -m "메시지"
주석 태그 생성
git push origin v1.0.0
태그 푸시
git push origin --tags
모든 태그 푸시
git tag -d v1.0.0
로컬 태그 삭제
git push origin :refs/tags/v1.0.0
원격 태그 삭제

常见问题

什么是Git?
Git是一个分布式版本控制系统,用于在软件开发中跟踪源代码的变更。

其他工具