Git致力于新分支

时间:2014-04-10 16:51:06

标签: git version-control git-branch git-commit

根据git文档,如果我想将更改保存到新分支,则标准产品是

1) git branch new_branch (assuming the branch hasn't been created)
2) git checkout new_branch
3) write new code
4) commit, and it automatically gets put in the new branch

但如果我按此顺序做事怎么办

1) write new code
2) git branch new_branch
3) ???

我现在如何将新代码保存到新分支?

2 个答案:

答案 0 :(得分:2)

同样的。

您可以在之后进行结账(因为它是一个新的分支)。

3) git checkout new_branch
4) commit, and it automatically gets put in the new branch

请注意,您还可以在一个命令中创建和签出:

git checkout -b new_branch

答案 1 :(得分:0)

将您的更改提交到当前分支。 然后从当前分支创建一个新分支。

$ git checkout -b new_branch currentbranch

结帐currentbranch

$ git checkout currentbranch

currentbrach重置为1次提交

$ git reset HEAD~1