【发布时间】:2017-12-09 02:49:21
【问题描述】:
我有几个 git 分支,它们之间有精心挑选的提交。提交有时会被压缩。
为了决定是否将提交 abcdef 应用到 live 分支,我想了解是否已经将等效提交应用到 preprod 分支。
如果preprod 从不压缩提交,我将使用补丁 ID,如 in this question 所述。由于preprod 可能会压缩提交序列,我想看看abcdef 是否会是preprod 上的空提交。
$ git checkout preprod
$ git cherry-pick abcdef
On branch preprod
Your branch is up-to-date with 'origin/preprod'.
You are currently cherry-picking commit abcdef.
The previous cherry-pick is now empty, possibly due to conflict resolution.
If you wish to commit it anyway, use:
git commit --allow-empty
Otherwise, please use 'git reset'
如何以编程方式检测挑选提交是否会导致空提交?
(我知道这是检测补丁是否已应用的不完善的启发式方法,但对于我的用例来说已经足够了。)
【问题讨论】:
-
您可以使用 bash 脚本中的
git diff并检查结果,而不是完全挑选。如果 git diff 显示没有差异,那么你应该很高兴。 stackoverflow.com/a/13715727/211627。不幸的是,压缩 prod 分支会更改历史记录,因此您已经消除了确定是否已应用补丁的最佳方法。我强烈建议不要在未来这样做。有点使代码版本控制工具的全部意义无效。
标签: git