Git 向后挑选两次提交之间的差异

标签 git git-rebase git-cherry-pick

我有以下提交:

repo dev---(222)---v1.0(111)

repo orig---v2.0(333)---

如何在提交 111 和 222 之间在存储库 A 中挑选差异(反向),然后使用 git 将结果提交到存储库 B 中?

我有一个包含更改(提交 222)的软件存储库 (dev),但这些更改是在与原始软件存储库 (orig) 无关的历史记录上完成的。

我做了以下操作(我的开发仓库是“dev”,原始仓库是“orig”):

  • 将原始存储库添加为“dev”存储库的远程跟踪
  • 查看了“orig”存储库提交“v1.0(111)”
  • 提交了对“dev”存储库的更改

现在我有了我的更改的反向差异: git diff v1.0(111) (222)

我想挑选这些更改并重新建立到“orig”存储库中的 v2.0(333)。

但是我确实在“How to cherry pick a range of commits and merge into another branch”中读到, “cherry-pick A..B”形式,A 应该比 B 更老。 如果顺序错误,命令将默默失败。

如何使用 git?

最佳答案

首先,cherry-pick 命令是

git checkout 333
git cherry-pick -n v1.0~...222
git commit -m "apply diff between 1.0 and 222"

您需要在 v1.0 的父级(因为 A 被排除)和 B

其次,由于您只想将一次提交应用于 333,因此请使用 -n 选项。

This flag applies the changes necessary to cherry-pick each named commit to your working tree and the index, without making any commit.

关于Git 向后挑选两次提交之间的差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44119402/

相关文章:

git - 将 bug 修复补丁从 release 分支 merge 到 master 分支

git - 'cherry' 在 git-cherry 中意味着什么?

git - 我们可以在已经与 master merge 的分支上提交吗?

git 和 Visual Studio

Git refs/stash 不为空但运行 git stash list 没有显示任何内容

Gitlab:每个用户的搜索提交

git - 交互式 rebase 后 Code Lens 无法正常工作

git - 如何在 rebase 期间快速标记有冲突的决议?

git - 在 Git 中,如何 rebase + 压缩历史记录中具有多个 merge 提交的分支,而不选择一个全新的分支

git - 对于特定提交,Git-merge 和 Git-cherry-pick 之间有什么区别?