本文翻译自:Push commits to another branch
Is it possible to commit and push changes from one branch to another. 是否可以将更改从一个分支提交到另一个分支。
Assume I commited changes in BRANCH1 and want to push them to BRANCH2 . 假设我在BRANCH1中提交了更改,并希望将其推送到BRANCH2中 。
From BRANCH1 , is it valid to do: 从BRANCH1执行以下操作是否有效:
git push origin **BRANCH2**
And then reset BRANCH1? 然后重置BRANCH1?
#1楼
参考:https://stackoom.com/question/wJQj/推送提交到另一个分支
#2楼
Certainly, though it will only work if it's a fast forward of BRANCH2 or if you force it. 当然,尽管仅当它是BRANCH2的快进或您强制使用时才起作用。 The correct syntax to do such a thing is 做这种事情的正确语法是
git push <remote> <source branch>:<dest branch>
See the description of a "refspec" on the git push man page for more detail on how it works. 有关其工作原理的更多详细信息,请参见git push手册页上“ refspec”的描述。 Also note that both a force push and a reset are operations that "rewrite history", and shouldn't be attempted by the faint of heart unless you're absolutely sure you know