我有以下提交:
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/