Take all my changes on the current branch and move them to a new branch in Git

早过忘川 提交于 2019-11-29 19:00:21

If you haven't been committing anything yet, you're already in the right position.

  1. Create a new branch: git checkout -b edge
  2. Your files haven't changed. Just git add what needs to and commit as usual.
  3. When you're done committing on edge, switch back to master with git checkout and git merge edge.

To add to JB's answer, if you have already started to make a few commits on master for what ended up as being a "edge" effort, you could:

git stash
git checkout -b edge master
git branch -f master SHA1_before_your_commits
git stash apply

If you are trying to move the work from master to a branch that already exists, but is behind master, git won't let you switch to the other branch. In this case, do this:

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