Why does Git switch my branches when I have modified files in the working folder?

前端 未结 2 675
慢半拍i
慢半拍i 2020-12-22 04:59

I have two branches. I changed some files while on one branch but did not add or commit them. The changes are in my working folder only. The changes are on tracked files but

2条回答
  •  清酒与你
    2020-12-22 05:29

    Branches point to commits. A "change" isn't part of a branch until you make a commit on that branch.

    Your working tree and index are not directly attached to a branch, so if you start doing some locally editing and then decide that you really wanted to make this change on a different branch you can check out that branch and carry on working.

    Git will refuse to change branches only if you have local modifications (staged or unstaged) which are based on files that are different between the branch that you are switching from and the branch that you are switching to.

提交回复
热议问题