작성
·
389
답변 1
2
좋은 질문 감사드립니다 :) 덕분에 저도 같이 공부했습니다.
아래 링크에서 답변 참고했습니다.
https://stackoverflow.com/questions/5798930/git-rm-cached-x-vs-git-reset-head-x
https://stackoverflow.com/questions/17122480/difference-between-git-rm-cached-and-git-reset-head
git rm --cached [file]
는 Track(git으로 관리)의 대상에서 제외하는 명령어이고,
git reset HEAD [file]
는 단순히 이전 단계로 reset 하는 명령어입니다.
예를 들어 버전 관리 하에 있는 A라는 파일을 변경한 뒤 add한 뒤에
`git rm --cached A` 명령어를 입력하면
아래와 같이 A는 Untracked files 로 남지만
$ git rm --cached A
rm 'A'
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
deleted: A
Untracked files:
(use "git add <file>..." to include in what will be committed)
A
git reset HEAD A 명령어를 이용해 staging area 에서 제거한다면
아래와 같이 여전히 tracking 되고 있다는 걸 확인할 수 있습니다.
$ git reset HEAD A
Unstaged changes after reset:
M A
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: A
no changes added to commit (use "git add" and/or "git commit -a")