commit 하기 전에 'git add' 한것을 되돌리는 방법.

LONGNEW·2020년 12월 25일
0

StackOverFlaw

목록 보기
3/16

Q. How do I undo 'git add' before commit?
Q. commit 하기 전에 'git add' 한거 뒤로 돌리려면 어떻게 해야 하나요?
I mistakenly added files to Git using the command:
제가 실수로 아래의 커맨드를 써서 파일을 Git 에 add 했습니다.

git add myfile.txt

I have not yet run git commit. Is there a way to undo this, so these files won't be included in the commit?
아직 git commit을 배운진 않았습니다. 커밋에 이 파일이 포함되지 않도록 되돌리는 방법이 있나요??


You can undo git add before commit with
사용자는 git add로 추가한 파일을 커밋 하기 전에 git reset 을 써서 되돌릴 수 있습니다.

git reset <file>

which will remove it from the current index (the "about to be committed" list) without changing anything else.
다른것은 바꾸지 않고 현재 가리키고 있는 index를 삭제합니다.

You can use
사용자는 git reset 을 이용해서

git reset

without any file name to unstage all due changes.
되돌릴 파일에 대한 이름 없이도 수행이 가능합니다.
This can come in handy when there are too many files to be listed one by one in a reasonable amount of time.
이것은 너무 많이 파일이 있어 하나씩 적기 힘들 때 매우 유용합니다.

In old versions of Git, the above commands are equivalent to git reset HEAD and git reset HEAD respectively, and will fail if HEAD is undefined (because you haven't yet made any commits in your repository) or ambiguous (because you created a branch called HEAD, which is a stupid thing that you shouldn't do).
옛날 버전에서 위의 커맨드는 git reset HEAD , git reset HEAD과 비슷합니다. 그리고 HEAD가 정의되지 않거나, 애매모호 할 경우엔 실행되지 않을 겁니다.
This was changed in Git 1.8.2, though, so in modern versions of Git you can use the commands above even prior to making your first commit:
이것은 Git 1.8.2에서 패치 되었는데, 인제는 위의 커맨드를 첫 커밋을 생성하기 전에도 이용할 수 있습니다.

"git reset" (without options or parameters) used to error out when you do not have any commits in your history, but it now gives you an empty index (to match non-existent commit you are not even on).
과거에는 "git reset"을 이용할 때 과거에 커밋 한 적이 없으면 에러를 표시했습니다. 지금의 경우엔 그저 빈 index를 반환 할 뿐입니다.


ambigous : 애매모호한
defined : 정의된

0개의 댓글