开发者

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

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 w开发者_Go百科ithout committing them to my master branch, so that the master still has my passing tests?


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.


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜