Git: Can I commit my working directory to a new branch without committing it to a current branch?

房东的猫 提交于 2019-11-30 14:40:31

问题


I am working on a project, and had all of my tests passing on the master branch. I then made some changes, and when everything started failing, I realized that maybe I should have made those changes on a different branch. Is there a way I can commit the changes to a new branch without committing them to my master branch, so that the master still has my passing tests?


回答1:


Yes, just create the new branch and check it out:

$ git checkout -b new-branch

Then commit any changes you have. They'll be applied to the new, checked-out branch.




回答2:


You can stash your current changes (git stash), switch to the new branch and then apply the changes to the new branch using

git stash pop


来源:https://stackoverflow.com/questions/2489559/git-can-i-commit-my-working-directory-to-a-new-branch-without-committing-it-to

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!