git cherry-pick 没有说要提交

git cherry-pick says nothing to commit

(注意:这不是重复问题,请参阅下面的解释)

我首先将 master 结帐为独立分支:

% git checkout --detach master
HEAD is now at fff9e1e687 modserver/go: skip Spotlight automod aspect ratio check for cheerio vids
Your branch is up to date with 'origin/master'.

然后我尝试挑选我的分支:

% git cherry-pick my_branch
Already up to date.
HEAD detached at refs/heads/master
You are currently cherry-picking commit 65b12d9d32.
  (all conflicts fixed: run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

nothing to commit, working tree 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 cherry-pick --skip'

根据 this 之前的 Whosebug post,这表明我正在挑选的提交不包含任何新更改。但是 git diff 说确实如此:

% git diff 65b12d9d32
diff --git a/ranking/acumen/datawizard/BUILD b/ranking/acumen/datawizard/BUILD
deleted file mode 100644
index 1d61abec2f..0000000000
--- a/ranking/acumen/datawizard/BUILD
+++ /dev/null
@@ -1,13 +0,0 @@
-load("//tools:go.bzl", "go_library")
-
-go_library(
-    name = "go_default_library",
-    srcs = [
-        "handler.go",
-    ],
-    visibility = ["//ranking/acumen:__subpackages__"],
-    deps = [
-        "//ranking/logging/log:go_default_library",
-        "@com_github_valyala_fasthttp//:go_default_library",
-    ],
-)
diff --git a/ranking/acumen/datawizard/handler.go b/ranking/acumen/datawizard/handler.go
deleted file mode 100644
index 388104cf57..0000000000
--- a/ranking/acumen/datawizard/handler.go
+++ /dev/null
@@ -1,22 +0,0 @@
-package datawizard

git diff 65b12d9d32 将提交 65b12d9d32 的树与您当前的工作副本进行比较。由于您的工作副本是干净的,因此相当于 git diff HEAD 65b12d9d32

另一方面,git cherry-pick 65b12d9d32 计算提交 65b12d9d32 与其 parent 之间的差异 - 由提交 65b12d9d32“引入”的更改。

您可以使用 git show 65b12d9d32git diff 65b12d9d32^ 65b12d9d32^ 表示“第一个 parent”)查看。

从那里开始,它可能与您链接的问题相同:Why is git-cherrypick saying nothing to commit?

使用 git stash 存储所有当前更改。

然后运行git cherry-pick -n {comitId}。如果您的分支与 {commitId} 之间存在任何差异,那么它将暂存到您当前的分支。

-n 与 cherry-pick 一起使用不会对您的分支进行提交。如果有任何更改,它只会暂存更改。

您现在可以使用 git diff 查看这些差异。

如果它显示没有任何变化,则表示来自 {commitId} 的代码已经在您当前的分支中。

如果它显示任何更改,那么您可以使用 git commit -m {message}

提交它们