Why do I have to stash / commit my changes before switching branches?

前端 未结 4 2076
不思量自难忘°
不思量自难忘° 2021-01-18 19:14

I find this to be annoying because I would like to quickly switch branches and do something and then switch back to what I was working on before. I realize I can stash and t

4条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-18 20:08

    You could use git checkout's --merge(-m) option.
    Using it causes a three-way merge to be done when switching branches. You may need to resolve merge conflicts if these occur.

    As to why this occurs, the manual states

    When switching branches, if you have local modifications to one or more files that are different between the current branch and the branch to which you are switching, the command refuses to switch branches in order to preserve your modifications in context.

    See the git checkout manual page for more details

提交回复
热议问题