-
카테고리
-
세부 분야
개발 도구
-
해결 여부
미해결
커밋 하나만 있을때 reset
21.10.28 23:07 작성 조회수 109
0
working directory, staging area에는 아무것도 없고 repository에 커밋 하나만 있는 상태에서는 어떻게 지워야 하나요?
soft, mixed, hard다 써봐도 안됩니다
답변을 작성해보세요.
1
강민철
지식공유자2021.10.29
하나의 버전만 있는 경우(첫번째 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
감사합니다
답변 1