开发者

How can I move my changes to a new branch after the fact?

I was working o开发者_如何转开发n my Rails project which is checked into Git. I read tutorials and they said for every time you start to change something, check out a branch.

However, accidentally I made some changes but did not check out a branch.

What should I do now?

What commands can I run so that Git takes my new changes and push them on my repository?


git stash
git checkout $correct_branch
git stash apply

Of course, if your changes are already on the branch you're going to put them on, just commit and go with it.

I hope you added a commit into jkp's answer. I can see somebody running that exact sequence without doing a commit and thus wiping out all their uncommitted changes...


It's not mandatory to make a branch, just best practice. It's perfectly legimate to work against master if you want. If you didn't create an explicit branch then you'll be working against master anyway and can push to that.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜