由于空格错误,git rebase 失败

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

git rebase failing due to whitespace error

gitrebase

提问by melder

I'm trying to rebase a branch and git is pooping out because it's attempting to perform some merge action which fails. How do I get git to stop this?

我正在尝试重新设置一个分支,而 git 正在输出,因为它正在尝试执行一些失败的合并操作。我如何让 git 阻止这个?

# git rebase -f --onto master~2 master~ master
First, rewinding head to replay your work on top of it...
Applying: r1002 - CS 1.0.23
Using index info to reconstruct a base tree...
M   about.html
<stdin>:68: trailing whitespace.                     
<stdin>:115: trailing whitespace.
<stdin>:201: trailing whitespace.
<stdin>:2369: trailing whitespace.
<stdin>:2385: trailing whitespace.
warning: squelched 2305 whitespace errors
warning: 2310 lines add whitespace errors.
Falling back to patching base and 3-way merge...
Auto-merging about.html
CONFLICT (content): Merge conflict in about.html
Failed to merge in the changes.
Patch failed at 0001 r1002 - 1002
The copy of the patch that failed is found in:
   /local/melder/tmp/test/.git/rebase-apply/patch

When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".

As you can see there are 2000+ whitespace errors, not something easy to merge by hand.

如您所见,有 2000 多个空白错误,手动合并并不容易。

Edit: to side step this for now without merging I did:

编辑:暂时不合并我做了:

# git add -A
# git rebase --continue
# git add -A
# git rebase --continue

Edit: nevermind that is a silly idea.

编辑:没关系,这是一个愚蠢的想法。

回答by joanpau

I faced the same problem today: rebase fails due to conflicts caused by whitespace errors. After failed trials with different settings for the whitespaceoption (git rebase --whitespace=fixand git rebase --whitespace=nowarn), the solution that worked for me was to ignore trailing whitespace errors in the recursive merging strategy (git rebase --abortany running rebase first if needed):

我今天遇到了同样的问题:由于空格错误引起的冲突,rebase 失败。在对whitespace选项 (git rebase --whitespace=fixgit rebase --whitespace=nowarn)进行不同设置的试验失败后,对我有用的解决方案是忽略递归合并策略中的尾随空格错误(git rebase --abort如果需要,首先运行任何变基):

git rebase -Xignore-space-at-eol <newbase>

Depenending on the kind of whitespace errors, options -Xignore-space-changeand -Xignore-all-spacemight be more useful. I don't know if the option --ignore-whitespacewould have also worked.

Depenending上的那种空白的错误,选项-Xignore-space-change-Xignore-all-space可能更为有用。我不知道该选项--ignore-whitespace是否也有效。

回答by Adam Dymitruk

that will not side step the issue. You now have conflict markers in your file!

这不会回避问题。您的文件中现在有了冲突标记!

The whitespace issue are warnings and you should not have as many legitimate conflicts. If the file is a nightmare to resolve, you may need to reconstruct it by hand. This depends on what you're doing though.

空格问题是警告,您不应该有那么多的合法冲突。如果文件难以解决,您可能需要手动重建它。这取决于你在做什么。

Many times the two bases are so different that each commit you are rebasing make you deal with this monstrous conflict. I tend to steer clear of rebase workflows and subscribe to merge/reset. Here's what I do: http://dymitruk.com/blog/2012/02/05/branch-per-feature/

很多时候,这两个基础是如此不同,以至于您重新定位的每次提交都会让您处理这种可怕的冲突。我倾向于避开 rebase 工作流并订阅合并/重置。这是我所做的:http: //dymitruk.com/blog/2012/02/05/branch-per-feature/

If your issues are only whitespace problems like line endings, you can try and clean up your repository by doing a filter branch or an interactive rebase on each side first to get whitespace on each commit to be consistent.

如果您的问题只是像行尾这样的空白问题,您可以尝试通过首先在每一侧执行过滤器分支或交互式变基来清理存储库,以使每次提交上的空白保持一致。

Also I use beyond compare 3 or Perforce Merge to do conflict resolutions. BC3 is syntax aware and should deal with whitespace the best. A lot of times, it won't even open up as it will resolve the conflicts for you and you can just continue.

我还使用 Beyond compare 3 或 Perforce Merge 来解决冲突。BC3 具有语法意识,应该最好地处理空白。很多时候,它甚至不会打开,因为它会为您解决冲突,您可以继续。

回答by mgarciaisaia

I think most diff viewers (specially those with a GUI) let you select how to handle whitespace changes.

我认为大多数差异查看器(特别是那些具有 GUI 的查看器)让您选择如何处理空白更改。

I'd suggest you to use something like meldas your git mergetoolto auto-correct those conflicts. When meldis launched, set it's whitespace-handling policy (from the Text filterstab of Preferencespanel), and it will auto-adjust those changes.

我建议你使用类似meld如您git mergetool对自动纠正这些冲突。当meld启动时,将其设置的空白处理政策(从Text filters选项卡Preferences面板),它会自动调整这些变化。

回答by Jeroen Vermeulen - MageHost

Today I solved such a problem this way:

今天我这样解决了这样一个问题:

REMOVE_AFTER="3cd7a0db76ff9dca48979e24c39b408c"
REPO="[email protected]:company/repo.git"
cd ~/tmp
git clone $REPO gitfix
cd gitfix
git checkout --orphan temp $REMOVE_AFTER
git commit -m "Truncated history"
git rebase --strategy=recursive --strategy-option=theirs --onto temp $REMOVE_AFTER master

When during the rebase you get a CONFLICT (modify/delete)conflict which is caused by a deleted file, you can solve it this way:

当在 rebase 期间遇到CONFLICT (modify/delete)由已删除文件引起的冲突时,您可以通过以下方式解决:

git rm path/to/both/deleted/file
git rebase --continue

When during the rebase you get an other conflict, you will need to manually fix it, and afterwards:

在变基期间遇到其他冲突时,您需要手动修复它,然后:

git add path/to/conflict/file
git rebase --continue

When you are finished, the rebase says All done.Then you can:

完成后,rebase 会显示All done.Then you can:

git branch -D temp

Now check the result:

现在检查结果:

git log --format=oneline