git add 실행 여부에 관계없이 분기 (수정, 추가, 삭제 된 파일)를 전환 할 때 왜 git에 변경 사항이 계속 표시됩니까?
나는 git을 처음 접했고 git checkout을 실행하여 분기 사이를 전환 할 때 왜 git이 다른 분기의 한 분기에서 변경된 것을 계속 표시하는지 이해하려고 노력했습니다. 먼저 git add를 사용하지 않고 작동하지 않았습니다. 그러나 git add를 사용해 보았지만 문제를 해결하지 못했습니다. 아직 git commit을 사용하고 있지 않습니다.
이것은 기본적으로 내가하고있는 일입니다.
$ git clone <a_repository>
$ git branch
* master
$ git branch testing
$ git checkout testing
...edit a file, add a new one, delete...
$ git status
# On branch testing
# Changed but not updated:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# deleted: file1.txt
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# file2.txt
no changes added to commit (use "git add" and/or "git commit -a")
$ git branch
master
* testing
$ git checkout master
D file1.txt
Switched to branch 'master'
$ git status
# On branch master
# Changed but not updated:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# deleted: file1.txt
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# file2.txt
no changes added to commit (use "git add" and/or "git commit -a")
브랜치를 사용하는 동안 한 브랜치에서 무엇을하든 다른 모든 브랜치에는 보이지 않습니다. 그것이 가지를 만드는 이유가 아닙니까?
"git add"를 사용하려고했지만 변경 사항이 두 가지 모두에 표시됩니다. 이것을 피하기 위해 브랜치를 전환하기 전에 "git commit"을 실행해야합니까?
Switching branches carries uncommitted changes with you. Either commit first, run git checkout .
to undo them, or run git stash
before switching. (You can get your changes back with git stash apply
)
Short answer: yes, you need to commit. Make sure you do it on the right branch, though!
A branch is a pointer to a commit. When you commit with a branch checked out, the branch advances to point to that new commit. When you check out a branch, you're checking out the commit it points to. (You can think of commits as snapshots of your work tree.)
So, if you have changes you haven't committed, they're going to be unaffected by switching branches. Of course, if switching branches is incompatible with your changes, git checkout
will simply refuse to do it.
git add
is a command for staging changes, which you will then commit. It does not record those changes into the history of the repository. It simply places them into a staging area (the index); git commit
then uses the contents of that staging area to create commits.
'IT story' 카테고리의 다른 글
Android-조각 ID 설정 (0) | 2020.08.06 |
---|---|
자바 스크립트의 고유 한 객체 식별자 (0) | 2020.08.06 |
json 매개 변수로 컬 GET 요청 (0) | 2020.08.06 |
C ++ 11이 지정된 초기화 목록을 C99로 지원하지 않는 이유는 무엇입니까? (0) | 2020.08.06 |
SQL Server 설치-설치 미디어 폴더 란 무엇입니까? (0) | 2020.08.06 |