Switching branches without touching the working tree?

前端 未结 5 525
無奈伤痛
無奈伤痛 2020-12-07 18:56

I am currently on a debug branch, and would like to switch to the master branch, without modifying the working tree (leave it the way it is in the debug branch), so I can co

5条回答
  •  忘掉有多难
    2020-12-07 19:06

    As far as I know, you can't. Branch switching means checking out into the working copy a version of the code that sits in the HEAD of that branch.

    You want to merge your branches. Do

    git checkout master
    git merge devel
    

    The branches will now be synchronized. If you want to merge a subset of changes, you can specify a commit or a range of commits. Also take a look at cherry-pick For example:

    git checkout master
    git cherry-pick devel
    

    Will merge the last commit in devel back into master.

    If you need to merge two branches that sit on different hosts, have a look at git pull and git push.

提交回复
热议问题