将当前分支的更改推送到其他分支
Push changes in current branch into other branch
我现在正在 dev
分支上工作。早些时候,我从 dev
分支创建了一个 featureX
分支,从那时起我已经向 dev
分支提交了 15 次。现在我想要 featureX
分支中的所有 15 次提交,这样我的 featureX
分支也可以拥有我上周在 dev
分支中完成的所有工作。
我对 rebase
、rebase --onto
等命令非常困惑。我应该使用其中之一吗?
听起来好像有三个 git 命令可能有用:rebase
, cherry-pick
, and merge
.
变基
The easiest way to integrate the branches...is the merge command. It performs a three-way merge between the two latest branch snapshots...and the most recent common ancestor of the two..., creating a new snapshot (and commit).
However, there is another way: you can take the patch of the change that was introduced...and reapply it on top. In Git, this is called rebasing. With the rebase command, you can take all the changes that were committed on one branch and replay them on a different branch.
在您的示例中,您可以执行以下操作:
git checkout featureX
git rebase dev
# continue your development on the featureX branch
# if there are conflicts, resolve them, and then continue with
git rebase --skip
# when done with changes, do:
git checkout dev
git merge featureX
摘樱桃
Apply the changes introduced by some existing commits.
在您的示例中,您可以执行以下操作:
git checkout dev
git cherry-pick ^HEAD dev
合并
将一个分支的更改合并到另一个分支。
在您的示例中,您可以执行以下操作:
git checkout featureX
git merge dev
所有示例和摘录均来自文档:
- https://git-scm.com/book/en/v2/Git-Branching-Rebasing
- https://git-scm.com/docs/git-cherry-pick#Documentation/git-cherry-pick.txt-codegitcherry-pickHEADmastercode
- https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging#_basic_merging
延伸阅读:
- Git merge master into feature branch
我现在正在 dev
分支上工作。早些时候,我从 dev
分支创建了一个 featureX
分支,从那时起我已经向 dev
分支提交了 15 次。现在我想要 featureX
分支中的所有 15 次提交,这样我的 featureX
分支也可以拥有我上周在 dev
分支中完成的所有工作。
我对 rebase
、rebase --onto
等命令非常困惑。我应该使用其中之一吗?
听起来好像有三个 git 命令可能有用:rebase
, cherry-pick
, and merge
.
变基
The easiest way to integrate the branches...is the merge command. It performs a three-way merge between the two latest branch snapshots...and the most recent common ancestor of the two..., creating a new snapshot (and commit).
However, there is another way: you can take the patch of the change that was introduced...and reapply it on top. In Git, this is called rebasing. With the rebase command, you can take all the changes that were committed on one branch and replay them on a different branch.
在您的示例中,您可以执行以下操作:
git checkout featureX
git rebase dev
# continue your development on the featureX branch
# if there are conflicts, resolve them, and then continue with
git rebase --skip
# when done with changes, do:
git checkout dev
git merge featureX
摘樱桃
Apply the changes introduced by some existing commits.
在您的示例中,您可以执行以下操作:
git checkout dev
git cherry-pick ^HEAD dev
合并
将一个分支的更改合并到另一个分支。
在您的示例中,您可以执行以下操作:
git checkout featureX
git merge dev
所有示例和摘录均来自文档:
- https://git-scm.com/book/en/v2/Git-Branching-Rebasing
- https://git-scm.com/docs/git-cherry-pick#Documentation/git-cherry-pick.txt-codegitcherry-pickHEADmastercode
- https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging#_basic_merging
延伸阅读:
- Git merge master into feature branch