This question already has an answer here:
这个问题在这里已有答案:
- Why does Git switch my branches when I have modified files in the working folder? 2 answers
- 当我修改工作文件夹中的文件时,为什么Git会切换我的分支? 2个答案
I've created a branch as git branch my_branch
, then git checkout my_branch
, work in it, however when I switch back in master git checkout master
I do see these changes in master as well. I assume this should not be happening.
我已经创建了一个分支作为git branch my_branch,然后git checkout my_branch,在其中工作,但是当我切换回master git checkout master时,我确实也看到了master中的这些更改。我认为这不应该发生。
% git checkout my_branch
Switched to branch 'my_branch'
<I make my changes>
% git status
On branch my_branch
Changes not staged for commit:
...
% git checkout master
Switched to branch 'master'
% git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
...
<Shows the same changed files as in my_branch>
What am I possibly doing wrong?
我可能做错了什么?
Thanks.
谢谢。
1 个解决方案
#1
3
Uncommitted changes in either the working directory or the staging area (i.e. the index) do not belong to any branch yet. So when you checkout another branch, that does not affect those changes. git status
still shows them as, well, uncommitted.
工作目录或暂存区域(即索引)中未提交的更改尚不属于任何分支。因此,当您签出另一个分支时,这不会影响这些更改。 git status仍然显示为,未提交。
#1
3
Uncommitted changes in either the working directory or the staging area (i.e. the index) do not belong to any branch yet. So when you checkout another branch, that does not affect those changes. git status
still shows them as, well, uncommitted.
工作目录或暂存区域(即索引)中未提交的更改尚不属于任何分支。因此,当您签出另一个分支时,这不会影响这些更改。 git status仍然显示为,未提交。