如何将 git 更改从主分支应用到不同的分支

  • 本文关键字:分支 应用 git git
  • 更新时间 :
  • 英文 :


我有 3 个分支:

  • 主人
  • 测试1
  • 测试2

现在我确实对 master 添加了一些更改。

任务是:将这些更改应用于 test1 和 test2,但将这些分支与 master 分开保存。

它看起来很简单,但我无法做到这一点。

现在,我正在尝试将test1与master合并:

git checkout test1
git merge master # already up-to-date
git pull origin master # up-to-date
git push origin test1 # Everything up-to-date

结果中与主节点没有变化。

正在尝试变基:

git checkout test1
git rebase master
git status
On branch test1
Your branch and 'origin/test1' have diverged,
and have 1 and 7 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
git pull

通过"递归"策略进行合并。 您的分支比"origin/test1"领先 2 次提交。

这 2 个提交是什么?我在大师中有很多提交。

此外,当前分支中的 master 仍然没有变化。

所以我只能用

那么,如何正确应用来自 master 的最新提交?

git reset --hard origin/test1

为了从其他分支带来变化,使它们保持"独立"(就好像它们是在单独的分支上独立开发的一样(,我认为你应该尝试 git 樱桃挑选。 https://git-scm.com/docs/git-cherry-pick