git rebase 错误(“无法应用...”)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31069316/
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-09 03:20:24  来源:igfitidea点击:

Error with git rebase ("could not apply...")

gitgithubgit-svnrebasegit-rebase

提问by Pierre Lison

I'm the administrator of the GitHub repository https://github.com/plison/opendial. I would like to reduce the number of commits on the repository, since the repository already has a few thousand commits, many of whom are minor debugging changes that could easily be squashed together (especially the ones that are a few years old).

我是 GitHub 存储库https://github.com/plison/opendial的管理员。我想减少存储库上的提交次数,因为存储库已经有几千次提交,其中许多是小的调试更改,可以很容易地合并在一起(尤其是几年前的更改)。

I'm therefore trying to apply rebasing in order to squash together part of my commits. However, I've experience the following issue:

因此,我试图应用变基以将我的部分提交压缩在一起。但是,我遇到了以下问题:

  1. When I type e.g. git rebase -i HEAD~10, I get a quite long number of commit lines (much more than 10) in the interactive editor. What could be the reason?
  2. More importantly, once I close the interactive editor to start the rebasing, I systematically get the error message "error:could not apply ', even when I do not make any change to the commits(i.e. if I leave all lines as 'pick', without any modification or reordering).
  1. 当我输入 eg 时git rebase -i HEAD~10,我在交互式编辑器中得到了相当长的提交行数(远远超过 10 行)。可能是什么原因?
  2. 更重要的是,一旦我关闭交互式编辑器以开始重新定位,我系统地收到错误消息“错误:无法应用”,即使我没有对提交进行任何更改(即,如果我将所有行都保留为“选择” ,无需任何修改或重新排序)。

How can I solve these issues? It should be noted that the repository was automatically imported from a previous (SVN) repository hosted on Google Code. The conversion seemed so far to have worked well, but I'm wondering why I get these errors when trying to rebase my commits.

我该如何解决这些问题?应该注意的是,该存储库是从 Google Code 上托管的先前 (SVN) 存储库自动导入的。到目前为止,转换似乎运行良好,但我想知道为什么在尝试重新设置提交时会出现这些错误。

采纳答案by Greg Hewgill

The history of your project seems to contain a number of merge commits recently (presumably you made those). The presence of merge commits in what you want to interactively rebase usually causes problems. (An interactive rebase pretty much assumes a linear history, but merge commits are not linear.)

您项目的历史记录似乎最近包含了许多合并提交(大概是您进行了这些提交)。在您想要交互式变基的内容中存在合并提交通常会导致问题。(交互式 rebase 几乎假设线性历史,但合并提交不是线性的。)

Your project history also somehow seems to have twoparallel histories that are merged together in commit 11b3653 (use a tool like gitkor tigto see this, it's not shown well on Github's web interface).

您的项目历史似乎也有两个平行的历史,它们在提交 11b3653 中合并在一起(使用类似gitktig这样的工具来查看这个,它在 Github 的 Web 界面上没有很好地显示)。

I would suggest that you attempt to first flatten your history to get rid of the parallel histories, and to remove the merge commits. Then, once you have a strictly linear history, you can set about rewriting the history to remove all the debugging churn.

我建议您首先尝试展平历史以摆脱并行历史,并删除合并提交。然后,一旦您拥有严格的线性历史记录,您就可以着手重写历史记录以消除所有调试流失。

回答by Somaiah Kumbera

As a reminder to myself on how to resolve this:

提醒自己如何解决这个问题:

The error message is not very informative. If you type

错误消息的信息量并不大。如果你输入

git rebase --continue

you realize the error is because of a merge conflict that git cannot resolve by itself, and needs your help.

您意识到错误是由于 git 无法自行解决的合并冲突,需要您的帮助。

To see what files have conflicts, type

要查看哪些文件有冲突,请键入

git status

Resolve the merge conflicts in your favorite editor/IDE (hint: this should start with i and end with ntelliJ)

解决您最喜欢的编辑器/IDE 中的合并冲突(提示:这应该以 i 开头并以 ntelliJ 结尾)

Mark resolution with

标记分辨率

git add .

If all the conflicts are resolved, you should see something like this:

如果所有冲突都解决了,您应该会看到如下内容:

(all conflicts fixed: run "git rebase --continue")

So continue your rebase with

所以继续你的变基

git rebase --continue

Hopefully your rebase should now be successful

希望你的 rebase 现在应该成功

git status

shows:

显示:

On branch feature/DIG-19302-Upgrade-mockito-v2
Your branch is behind 'origin/feature/your-feature-branch' by 2 commits, and can be fast-forwarded.
(use "git pull" to update your local branch)

nothing to commit, working directory clean

Don't do a git pull. If you do, you will only overwrite your merge conflicts. Instead push your merge conflict resolutions to the branch) with

不要做 git pull。如果这样做,您只会覆盖合并冲突。而是将您的合并冲突解决方案推送到分支)与

git push --force

You're done! Your git log should show only 1 commit now (which is the forced update you just did)

你完成了!你的 git 日志现在应该只显示 1 个提交(这是你刚刚做的强制更新)