ProgramingTip

git 파일을 스테이징 영역 버전으로 되돌리려면 어떻게해야합니까?

bestdevel 2020. 11. 5. 08:24
반응형

git 파일을 스테이징 영역 버전으로 되돌리려면 어떻게해야합니까?


라는 파일이 가정 해 보겠습니다 a.txt. 스테이징 영역에 추가 한 다음 수정합니다. 추가했을 때의 상태로 되돌리려면 어떻게해야합니까?


git checkout a.txt

다음을 입력하면 Git이 알려드립니다 git status.

# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
# modified:   a
#
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified:   a
#

git checkout -- a.txt

이 페이지의 다른 대답에는 --혼란이 발생했습니다.

다음을 입력 할 때 Git이 알려주는 내용입니다 git status.

# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
# modified:   a
#
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified:   a
#


준비된 파일 준비 해제

다음 두 섹션에서는 스테이징 영역 및 디렉토리 변경 작업 방법을 보여줍니다. 좋은 점은이 두의 상태를 확인하는 데 사용하는 명령이 변경 사항을 취소하는 방법을 상기시켜 준다는 것입니다. 예를 들어, 두 개의 파일을 변경하고 두 개의 인화 변경 사항을 커밋하려고하지만 실수로 git add *를 입력하고 둘 다 스테이징 가정 해 보겠습니다. 둘 중 하나를 어떻게 어떻게 해제 할 수 있습니까? git status 명령은 다음을 알려줍니다.

$ git add *
$ git status

On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)

renamed:    README.md -> README
modified:   CONTRIBUTING.md

“Changes to be commit”텍스트 바로 아래에 git reset HEAD ...를 사용하여 unstage라고 표시되어 있습니다. 따라서이 조언을 사용하여 CONTRIBUTING.md 파일을 언 스테이징 해 보겠습니다.

$ git reset HEAD CONTRIBUTING.md
Unstaged changes after reset:
M   CONTRIBUTING.md

$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)

renamed:    README.md -> README

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:   CONTRIBUTING.md

명령이 약간 이상하지만 작동합니다. CONTRIBUTING.md 파일이 수정 다시 한 번 준비 해제되었습니다.

참고 URL : https://stackoverflow.com/questions/3044684/how-do-you-revert-a-git-file-to-its-staging-area-version

반응형