상황별 복구 방법
| 상황 | 명령어 |
|---|---|
| 스테이징 취소 | git restore --staged <file> |
| 작업 디렉터리 되돌리기 | git restore <file> |
| 마지막 커밋 수정 | git commit --amend |
| 커밋 되돌리기 (히스토리 유지) | git revert HEAD |
| 커밋 취소 (히스토리 삭제) | git reset HEAD~1 |
| 작업 임시 저장 | git stash |
| 삭제된 커밋 복구 | git reflog |
스테이징/작업 디렉터리 되돌리기
Bash
git restore --staged index.html
git restore index.html
git restore --staged .
git restore .커밋 수정 (push 전에만)
Bash
git commit --amend -m "fix: 올바른 메시지"
git add forgotten.txt
git commit --amend --no-editreset
Bash
git reset --soft HEAD~1 # 커밋만 취소, 변경사항은 스테이징으로
git reset HEAD~1 # 커밋 취소 + 스테이징 해제, 파일은 유지
git reset --hard HEAD~1 # 커밋 + 변경사항 모두 삭제 (위험)
git reset --hard abc1234revert (공유 브랜치)
Bash
git revert abc1234
git revert --no-commit HEAD~3..HEAD
git commit -m "revert: 마지막 3개 커밋 되돌리기"stash
Bash
git stash
git stash push -m "로그인 기능 WIP"
git stash list
git stash pop
git stash apply stash@{1}
git stash drop stash@{0}
git stash branch feat/new stash@{0}reflog (삭제된 커밋 복구)
Bash
git reflog
git reset --hard HEAD@{3}
git reflog | grep "feat/login"
git checkout -b feat/login abc1234편집 안내 · Editorial Note
이 가이드는 AI 도구를 활용해 초안을 구성하고 사람이 명령어·문맥을 검토해 발행했습니다. 운영체제와 도구 버전에 따라 결과가 달라질 수 있으므로 적용 전 공식 문서를 함께 확인하세요. 오류를 발견하시면 이메일로 제보해 주세요.
관련 공식 문서Git 공식 문서 ↗
질문 & 답변 (Q&A)
이 가이드에 대해 궁금한 점을 질문해보세요. 확인 후 답변드립니다.