To git checkout without overwriting data

前端 未结 3 1020
野趣味
野趣味 2021-02-01 03:35

How can you git-checkout without overwriting the data?

I run

 git checkout master

I get

         


        
3条回答
  •  北荒
    北荒 (楼主)
    2021-02-01 03:53

    Git does a 2-way merge of uncomitted changes when switching branches (using git checkout ), but ordinarily it does only trivial (tree-level) merge.

    Besides git-stash solution by Karl Voigtland, you can give additional options to git checkout, choosing one of the following options:

    • Tell git to try harder to merge uncomitted changes into branch you switch to with -m / --merge option. 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.

    • Tell git to overwrite uncomitted changes, throwing away local changes with -f option. Warning: uncomitted changes will be lost!

提交回复
热议问题