search

Home  >  Q&A  >  body text

git - 如何将当前修正内容commit到一个新的branch?

比如在master下,修改/新建了文件。 此时发现这样的修正需要到另一个分支下进行。 如何将当前工作直接提交到一个新的branch中? 提交后,当前master变成clear工作目录。

ringa_leeringa_lee2800 days ago877

reply all(3)I'll reply

  • 巴扎黑

    巴扎黑2017-04-22 09:01:32

    As coder said, just create a new branch and cut to it.

    However, if you want to switch to an existing branch, for example, after making changes, you find that you should commit on another existing branch, there may be a conflict when switching over. At this point you need to use the stash function:

    git stash
    git checkout other_branch
    git stash pop
    git commit -av # or whatever
    

    reply
    0
  • PHP中文网

    PHP中文网2017-04-22 09:01:32

    You only need to execute the command to create a branch under the current branch:

    git checkout -b newbranch
    

    reply
    0
  • PHP中文网

    PHP中文网2017-04-22 09:01:32

    git checkout New branch

    git cherry-pick master

    reply
    0
  • Cancelreply