开发者

How to operate a local branch in git

From here, http://cheat.errtheblog.com/s/git, I think I can recreate a branch in my local repository by

$ git branch mytestbranch
<then I can may changes as my experimental>

My question is how can

  • I forget all the changes I made in the 'mytestbranch' branch? and switch back to my original 's stage/version 开发者_如何转开发of my repository?
  • I keep the changes I made and move every thing to my 'main' branch?

Thank you.


If you want to forget everything that you did in mytestbranch and you don't want to use any of those changes, you don't have to do much, just switch to master and delete the branch:

git checkout master
git branch -D mytestbranch

If you want to merge all the changes you made in mytestbranch just do merge:

git checkout master
git merge mytestbranch
git branch -d mytestbranch

The difference between git branch -D and git branch -d is that the former can delete branches that have not been fully merged into HEAD.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜