Git add 취소하기

sobu·2020년 12월 15일
0

Intro

언젠가는 한 번쯤 git add -all을 했는데 원하지도 않는 파일들이 Add되 본 적이 있을 것이다. 숨겨져 있던 파일들이 Add된다던지...

git restore --staged file_name

그럴 때 쓰는 것이 git restore --staged file_name이다. git add --all한 상태에서 Cmd창에서 git status를 치면

C:\Users\jun\workspace\project>git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   requirements.txt
        modified:   test.txt

위와 같은 메세지를 볼 수 있는데, git에서 조언해주는 내용만 잘 읽어봐도 무엇을 해야하는지 알수 있다.
git reset HEAD file_name 또한 위와 같이 쓸수도 있다.

Add 취소를 위해 git restore --staged test.txt를 입력하자.

Outro

Add를 취소한 상태에서는

C:\Users\jun\workspace\project>git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   requirements.txt

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   test.txt

위와 같은 안내 문구가 나오는 것을 볼 수 있을 것이다.

오늘의 교훈은 git에서 조언해주는 내용을 잘 읽어보자는 것이다.

profile
Maybe, Am I human?

0개의 댓글