git reset
git
쓰는 꼴
git reset [--soft|--mixed|--hard] <commit> | git reset <path>브랜치가 가리키는 커밋을 옮깁니다 — --soft는 변경을 스테이지에 남기고, --mixed(기본)는 스테이지만 풀어 수정은 파일에 두며, --hard는 파일의 수정까지 함께 버려 되찾을 수 없습니다.
자주 쓰는 옵션
| 옵션 | 뜻 |
|---|---|
| --soft | move the branch only; index and files keep everything, so the change stays staged |
| --mixed | default: also clear the staging area, leaving edits in your files |
| --hard | also overwrite your files; uncommitted work is destroyed |
| <path> | no commit given: unstage that path |
| --keep | move but refuse if it would overwrite a local change |
| --merge | like --hard but keeps changes that do not collide |
예시
git reset --soft HEAD~1undoes the last commit and leaves everything staged
git reset HEAD~1undoes the last commit; the changes sit in your files, unstaged
git reset src/app.tsunstages one file without changing it
git reset --hard origin/mainthrows away local commits AND uncommitted edits
되돌리는 방법이 여럿이라 헷갈립니다 — 가리키는 곳을 옮기는 것과 새 커밋을 얹는 것은 다릅니다.
읽는 방법
- 대괄호 [ ]는 넣어도 되고 안 넣어도 되는 자리입니다.
- 점 셋 …은 여러 개를 이어 쓸 수 있다는 뜻입니다.
- 옵션은 대소문자를 가립니다 — -r과 -R이 다른 명령도 있습니다.
자주 묻는 것
Q. git reset은 무엇을 하나요?
브랜치가 가리키는 커밋을 옮깁니다 — --soft는 변경을 스테이지에 남기고, --mixed(기본)는 스테이지만 풀어 수정은 파일에 두며, --hard는 파일의 수정까지 함께 버려 되찾을 수 없습니다.
Q. 어떻게 치나요?
git reset [--soft|--mixed|--hard] <commit> | git reset <path> — 대괄호는 생략할 수 있는 자리입니다.
Q. 옵션은 몇 개나 자주 쓰나요?
여기 정리한 것은 6개입니다. 전체 목록은 man git에 있습니다. 이 명령은 git 갈래입니다.
같이 보는 명령
man 페이지: man git-reset