git cherry-pick 不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7072013/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 11:34:57  来源:igfitidea点击:

git cherry-pick not working

gitbranching-and-mergingcherry-pick

提问by Jay Taylor

I'm trying to cherry-pick a commit from master and get it into the current production branch. However, when I execute git cherry-pick <SHA-hash>, I just get this message:

我正在尝试从 master 中挑选一个提交并将其放入当前的生产分支。但是,当我执行时git cherry-pick <SHA-hash>,我只收到此消息:

# On branch prod_20110801
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#   site/test-result/
 nothing added to commit but untracked files present (use "git add" to track)
 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'

Note: I've tried doing a reset and a reset --hard HEAD^, and neither seemed to change anything.

注意:我尝试过重置和重置 --hard HEAD^,但似乎都没有改变任何东西。

I'm confused as to why this isn't working for me.

我很困惑为什么这对我不起作用。

Any insight, advice, or ideas on how to resolve this would be helpful~!

任何有关如何解决此问题的见解、建议或想法都会有所帮助~!

回答by cdhowie

Git is resolving the cherry-pick as a no-op -- all of the changes introduced by that commit have been introduced by some commit on your current branch. (Or that's what Git thinks, anyway.) Verify that the commit you are cherry-picking hasn't already been merged somehow, as either a proper merge, rebase/cherry-pick, or piecemeal patch. (Use git show <commit-id>to see the diff.)

Git 正在将cherry-pick 解析为无操作——该提交引入的所有更改都已由当前分支上的某个提交引入。(或者这就是 Git 的想法,无论如何。)验证您正在挑选的提交尚未以某种方式合并,无论是适当的合并,rebase/cherry-pick,还是零碎的补丁。(git show <commit-id>用于查看差异。)

回答by pkamb

In my case this was driving me nuts, as it was quite obvious that the specific commit I wanted to cherry pick had notbeen merged into my current branch.

在我而言这是推动我坚果,因为这是很明显的,具体的承诺,我想挑樱桃就没有被合并到我目前的分支。

It turns out someone had alreadycherry picked the commit a week prior. The changes, but not the specific SHA, were already in my current branch, and I had not noticed them.

事实证明,有人已经在一周前挑选了提交。的变化,而不是特定的SHA,已经在我目前的分支,我没有注意到它们。

Check the file(s) that you're attempting to cherry pick. If they already have the changes, a version of the commit has already been cherry picked or added in another manner. There is thus no need to cherry pick it again.

检查您尝试挑选的文件。如果他们已经有了更改,则提交的一个版本已经被挑选出来或以其他方式添加。因此没有必要再次挑选它。

回答by Neamar

Also note that adding an empty file (e.g. .gitkeep) to the tree is considered by cherry-pick as an empty commit.

另请注意,向.gitkeep树添加空文件(例如)被cherry-pick 视为空提交。

回答by msouth

So, here's Yet Another Confusing Situation where this can arise: I had the following:

所以,这是可能出现的另一种令人困惑的情况:我有以下几点:

git log screenshot

git日志截图

I was trying to cherry pick 9a7b12e which is apparently nothing--it even tried to tell me on that line in the git log output that 4497428 was what I really wanted. (What I did was just looked for the commit message and grabbed the first hash I saw that had it). Anyway, just wanting to let people know that there's another way you can get tricked into trying to cherry pick a no op.

我试图挑选 9a7b12e 显然什么都不是——它甚至试图在 git log 输出的那一行告诉我 4497428 是我真正想要的。(我所做的只是查找提交消息并获取我看到的第一个哈希值)。无论如何,只是想让人们知道还有另一种方法可以欺骗您尝试选择无操作。