我有 2 个分支:FeatureBranch
和 ReleaseBranch
。
我确实从 FeatureBranch
到 ReleaseBranch
挑选了一个提交 c1
的文件。
后来我对 FeatureBranch
上的同一文件做了一些修改,并使用 id c2
提交。
我再次增强了 FeatureBranch
上的同一文件,并使用 ID c3
提交。
现在我不想将 c2
放到 ReleaseBranch
上,我只需要 c3
。我尝试直接使用 c3
id 进行挑选,但 Git 返回了错误:
could not apply c3...
我知道 Git 中的索引是增量的,因为我不希望 c2
更改,而我只需要 c3
。有什么办法可以实现这一点吗?
最佳答案
第一:您正在维护两个不同版本的代码,一个在 FeatureBranch
上,一个在 ReleaseBranch
上。您开始看到拥有两个“实时”版本代码的负面影响。
我不知道您的限制是什么,但“将功能集成到发布中,或放弃功能”应该成为您近期计划中的优先里程碑。
您在该文件上遇到了冲突。 git 无法直接应用 c3
,因为 c2
引入了一些更改,这些更改将补丁 c2 -> c3
变成了无法应用的内容在发布
上。
您必须手动编辑冲突来修复它,然后提交结果。
如果c2
中的更改很容易丢弃,另一种方法是丢弃当前的cherry-pick,获取文件的完整内容,然后对其进行编辑以删除不需要的更改想要在发布时提交:
# -- from ReleaseBranch
# cancel the cherry-picking :
git cherry-pick --abort
# get the content of the file stored in c3 (will contain modifs from c1+c2+c3) :
git checkout c3 -- path/to/file
# edit the file to remove unwanted code ...
# add and commit
git add path/to/file
git commit
关于git - 如何挑选文件的特定提交?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32986219/