To git checkout without overwriting data

前端 未结 3 1017
野趣味
野趣味 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 04:03

    You can do a git reset --soft to make your HEAD point to the new branch, but leave all the files as they are (including the ones that were changed in the new branch). Then you can use git checkout to checkout just the files that you really want from the new branch.

           git reset [] []
               This form resets the current branch head to  and possibly updates the index (resetting it to the
               tree of ) and the working tree depending on . If  is omitted, defaults to --mixed.
               The  must be one of the following:
    
               --soft
                   Does not touch the index file or the working tree at all (but resets the head to , just like
                   all modes do). This leaves all your changed files "Changes to be committed", as git status would put
                   it.
    

提交回复
热议问题