为什么"git rebase"只用空格提交给"error: patch does not apply"?



我在做出唯一更改的提交后试图折叠时会出现以下错误:

First, rewinding head to replay your work on top of it...
Applying: other-branch: modify myfile-1: add leading whitespace
Using index info to reconstruct a base tree...
error: patch failed: myfile-1:1
error: myfile-1: patch does not apply
error: Did you hand edit your patch?
It does not apply to blobs recorded in its index.
Patch failed at 0001 other-branch: modify myfile-1: add leading whitespace
The copy of the patch that failed is found in: .git/rebase-apply/patch

我可以避免以下错误: git rebase -Xignore-space-change master

我想了解正在发生的事情。

Q1:是什么原因导致此错误发生?

Q2:为什么我会看到git rebase的错误,而不是git commit

命令重现:

export GIT_DIFF_OPTS=-u0
cd /tmp
rm -fr my-repo
git init my-repo
cd my-repo
cat > myfile-1 << EOF
line 1
line 2 (note that 2 lines are necessary to reproduce)
EOF
git add .
git commit -am 'master: no leading whitespace in myfile-1'
git checkout master
git checkout -b other-branch
cat > myfile-1 << EOF
      line 1
line 2 (note that 2 lines are necessary to reproduce)
EOF
git commit -am 'other-branch: modify myfile-1: add leading whitespace'
git checkout master
echo foo > myfile-2
git add .
git commit -am 'master: non-conflicting commit (add myfile-2)'
git checkout other-branch
git rebase master  # this fails -- why?
git rebase --abort
git rebase -Xignore-space-change master  # this succeeds

解决方案: GIT_DIFF_OPTS=-U0(不是 GIT_DIFF_OPTS=-u0(

我发现此错误是由:
引起的 GIT_DIFF_OPTS=-u0
设置在我的环境中。这是一个错误 - 我真正想要的是:
GIT_DIFF_OPTS=-U0
(大写U,将上下文的差异线设置为0(。

git diff-u选项告诉其创建一个补丁,该补丁以某种方式导致问题中显示的git rebase错误。

最新更新