Switch to another branch without changing the workspace files

前端 未结 8 1407
深忆病人
深忆病人 2021-01-30 06:26

I cloned a git repository from GitHub, made some changes and some commits; I made quite a lot and all are quite dirty, so they\'re not suitable for a pull request. Now I created

相关标签:
8条回答
  • 2021-01-30 07:13

    Edit: I just noticed that you said you had already created some commits. In that case, use git merge --squash to make a single commit:

    git checkout cleanchanges
    git merge --squash master
    git commit -m "nice commit comment for all my changes"
    

    (Edit: The following answer applies if you have uncommitted changes.)

    Just switch branches with git checkout cleanchanges. If the branches refer to the same ref, then all your uncommitted changes will be preserved in your working directory when you switch.

    The only time you would have a conflict is if some file in the repository is different between origin/master and cleanchanges. If you just created the branch, then no problem.

    As always, if you're at all concerned about losing work, make a backup copy first. Git is designed to not throw away work without asking you first.

    0 讨论(0)
  • 2021-01-30 07:14

    Git. Switch to another branch

    git checkout branch_name
    
    0 讨论(0)
提交回复
热议问题