为什么当我在 'X' 分支中进行更改时,我的主分支也会以相同的方式更改?

Why when I make a change in 'X' branch my master branch is changing as well in the same way?

我有一个 master 分支:

然后我从 master 创建 employee 分支并稍微改变一下:

当我在分支之间滑动时,master 分支也发生了变化:

我不知道为什么会这样。

有什么建议可以return恢复正常吗?

当您在编辑器中进行更改时,您只修改 "working directory" 中的代码。当您切换分支时,"dirty" 目录中的那些更改也会随之而来。

在给定分支上提交更改后,切换分支将不再带来这些更改。

当您在编辑器中进行更改时,您只需修改 "working directory" 中的代码。当您切换分支时,"dirty" 目录中的那些更改也会随之而来。

在给定分支上提交更改后,切换分支将不再带来这些更改。

(@Joseph Silber 的回答)

在处理您的案件之前,您可以做出三个选择:

A) 在主分支中维护变更

# Agree 
git add file/path/archive
# Perfom a commit
git commit -m "Message"

B) Return分公司员工并在此分公司添加变更

# Since the terminal gitbash or the manually form
git checkout employee
# Agree 
git add file/path/archive
# Perfom a commit
git commit -m "Message" 

C) 放弃所有更改

此步骤将撤消之前未添加到提交中的所有更改。注意!!

git checkout file/path/archive

确保您提交到“X”分支。提交到“X”分支后,main/master 分支中不会发生任何更改。但是如果你切换主分支而不提交到“X”分支,那么主分支也会看到变化。