git: cherry-pick 的不同可能输出

git: different possible output of cherry-pick

我正在尝试编写一个自动执行 git cherry-pick 的脚本。我需要能够处理 git cherry-pick 的所有可能失败。到目前为止,我统计了 3 种输出:

+Cherry-pick 成功,没有合并冲突。退出代码为 0。输出如下所示:

git cp ed54dfc
[dev/nango/cp3_nocconflict 97f2dce] test cp1
1 file changed, 1 insertion(+)
create mode 100644 foo.txt

+Cherry-pick 提交已经在分支中的代码,或者没有代码被提交。退出代码 1。输出如下所示:

You are currently cherry-picking commit 61ff477.


It took 3.90 seconds to enumerate untracked files. 'status -uno'
may speed it up, but you have to be careful not to forget to add
new files yourself (see 'git help status').
nothing to commit, working directory clean
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'

+Cherry-pick 抛出合并冲突。退出代码 1:

error: could not apply ed54dfc... test cp1
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'

有没有其他cherry-pick的可能?我看了一下文档,没有太多提到 cherry-pick 的可能结果。

谢谢。

如果您想考虑所有可能的情况,您可以根据 git cherry-pick present in the git repo 的情况进行测试,即:

您可能不会再发现任何输出消息,但至少您会针对该命令的所有已知测试用例测试这些消息。