rm --cached filename과 reset HEAD -- filename의 차이점
464
작성한 질문수 2
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")
pull request에 관해
0
35
1
로컬과 원격의 상호작용 강의 질문
0
130
2
password authentication was removed
0
223
2
section3부터 맥북에서 화면이 안나옵니다.
0
206
2
Git bash 우클릭 보이지 않음
0
349
1
원격 저장소 조회(추가)
0
172
1
혹시 아래처럼 계속 파일을 찾을 수 없다는 건 어떤 의미일까요..
0
137
1
Git 맥북 다운로드
0
292
2
Git bash 다 마우스 우클릭해도 보이지 않습니다
0
412
2
pr 이후 브랜치 삭제 질문드립니다
0
947
2
블로그
0
255
2
github에서 push오류
0
261
1
reset에서 head
0
332
1
git branch 관련 질문
0
217
1
Section 2 / 4강 / 3:23초 질문
0
166
1
diff & revert
0
267
1
이슈 번호를 잘못 명시한 커밋을 삭제하는 방법
0
1179
1
강의 "로컬과 원격의 상호작용 실습 (+충돌이 난 경우)" 편의 영상 7분 38초 쯤에서 질문 드립니다.
0
416
1
mac사용
0
304
1
원격 branch를 checkout 하면서 새 branch를 만드는 방법
0
441
1
git checkout 과 git switch/restore
0
2421
1
로컬 브랜치 관련 질문합니다.
0
196
3
git stash, git tag 에 대한 강의자료가 있으면 좋겠습니다
0
300
1
브랜치를 main(master) 와 동기화 하고 싶을 때
0
9141
1





