인프런 커뮤니티 질문&답변
커밋 하나만 있을때 reset
작성
·
234
퀴즈
`git reset --hard` 명령이 워킹 디렉토리, 스테이징 영역, 저장소에 미치는 영향은 무엇일까요?
저장소만 지정된 커밋으로 되돌립니다.
워킹 디렉토리, 스테이징 영역, 저장소 모두 지정된 커밋 상태로 초기화합니다.
스테이징 영역과 저장소만 되돌리고 워킹 디렉토리 변경사항은 유지합니다.
워킹 디렉토리와 스테이징 영역만 되돌리고 저장소는 그대로 둡니다.
답변 1
1
강민철
지식공유자
하나의 버전만 있는 경우(첫번째 commit의 경우)는 revert나 reset이 되지 않습니다.
첫번째 commit의 경우 아래 명령어를 통해 commit을 되돌릴 수 있습니다
$ git update-ref -d HEAD
이는 현재 head가 위치한 공간에서 관리되는 git 정보를 삭제하라는 명령어입니다.
예제는 아래와 같습니다.
mckang@P22009003-mckang MINGW64 /c/test_dir (master)
$ git status
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
test.txt
nothing added to commit but untracked files present (use "git add" to track)
mckang@P22009003-mckang MINGW64 /c/test_dir (master)
$ git add .
warning: LF will be replaced by CRLF in test.txt.
The file will have its original line endings in your working directory
mckang@P22009003-mckang MINGW64 /c/test_dir (master)
$ git commit -m "initial commit"
[master (root-commit) f619bf6] initial commit
1 file changed, 1 insertion(+)
create mode 100644 test.txt
mckang@P22009003-mckang MINGW64 /c/test_dir (master)
$ git status
On branch master
nothing to commit, working tree clean
mckang@P22009003-mckang MINGW64 /c/test_dir (master)
$ git update-ref -d HEAD
mckang@P22009003-mckang MINGW64 /c/test_dir (master)
$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: test.txt
mckang@P22009003-mckang MINGW64 /c/test_dir (master)
$ git add .
mckang@P22009003-mckang MINGW64 /c/test_dir (master)
$ git commit -m "modified commit"
[master (root-commit) 3a69354] modified commit
1 file changed, 1 insertion(+)
create mode 100644 test.txt
mckang@P22009003-mckang MINGW64 /c/test_dir (master)
$ git log
commit 3a693541c03284835cfb8ac04eb34c9417be2cca (HEAD -> master)
Author: Kang Minchul <tegongkang@gmail.com>
Date: Fri Oct 29 15:23:38 2021 +0900
modified commit
감사합니다





