git switch branch without discarding local changes

后端 未结 6 1092
死守一世寂寞
死守一世寂寞 2020-11-30 16:48

Alright, lets say one day we make happen to make a bunch of modifications and when we go to commit them we notice we were working on the wrong branch.

How can we for

6条回答
  •  余生分开走
    2020-11-30 17:27

    You could use --merge/-m git checkout option: git checkout -m

    -m --merge

    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. However, with this option, a three-way merge between the current branch, your working tree contents, and the new branch is done, and you will be on the new branch.

    Source: https://git-scm.com/docs/git-checkout

提交回复
热议问题