git rebase: "error: patch does not apply" with whitespace-only commit
git rebase: "error: patch does not apply" with whitespace-only commit
在进行唯一更改是添加前导空格的提交后尝试变基时出现以下错误:
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:是什么原因导致这个错误发生?
问题 2:为什么我在 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
错误。
在进行唯一更改是添加前导空格的提交后尝试变基时出现以下错误:
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:是什么原因导致这个错误发生?
问题 2:为什么我在 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
错误。