为什么一个分支的更改会影响 git 中的另一个分支?

Why changes in one branch can affect the other branch in git?

  1. 我在 master 分支,
  2. 我承诺一切
  3. 然后我创建一个新分支"git checkout -b xxx"
  4. 然后我切换回 master "git checkout master"
  5. 然后我在不使用 "git rm"
  6. 的情况下删除了 master 分支的所有内容
  7. 我checkout到xxx分支,在分支切换的过程中,它显示了一个很长的列表,每个文件都有一个状态'D'
  8. 然后我发现分支 xxx 也有一个空文件夹。

这不是问题,因为我可以使用 "gt reset --hard HEAD"

在分支 xxx 中恢复

我只是想知道为什么删除一个分支的行为会影响另一个分支?分店不是都存了吗?

为了更好地理解 git 分支,如果您使用 Windows,请尝试使用应用程序 "Git Extensions"。这个应用程序显示了你的仓库中的所有分支,并且它更容易理解。

  1. then I tried to merge one of my branch using "git merge xxx", it said "alread update to date"

发生这种情况是因为您的 xxx 分支已经合并到 master 并且 xxx[=30= 中没有任何变化] 之后

  1. I checkouted to branch xxx, during the branch switching, it shows a long list that every file had a status 'D'

您尚未提交更改并切换到分支 xxx,因此您的所有更改都已移至该分支

I just wonder why deleting behavior at one branch can affect the other branch? Doesn't the branch stored everything?

是的。但是你在没有提交的情况下在分支之间移动你的更改,所以你可以在每个 "up-to-date" 分支中看到它。只需将它提交到某个地方,它就会像预期的那样运行

编辑: 删除文件与修改 git 的操作相同,因此您必须在 删除 之后提交更改,介于步骤 5 和 6

之间