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

前端 未结 2 658
慢半拍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.

    0 讨论(0)
  • 2020-12-22 05:46

    You are probably referring to un-tracked files, not changed files. Un-tracked files where never added or committed to any branch, and they stick around when you switch branches.

    If you change a tracked file, git won't let you switch branch until you do something with it (commit, discard the change, etc...).

    0 讨论(0)
提交回复
热议问题