• 카테고리

    질문 & 답변
  • 세부 분야

    개발 도구

  • 해결 여부

    미해결

rm --cached filename과 reset HEAD -- filename의 차이점

21.01.09 16:08 작성 조회수 277

1

git에서 staging area에 있는 file을 unstage하기 위해

git status를 했을 때 표시하는 명령이 git rm --cached filename이던데

git reset HEAD -- filename과 차이점이 뭔가요?

겉보기에 unstage하는 건 똑같아 보여서요.

답변 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")