尝试应用git diff时,错误是“输入中无效的补丁”。
我正在创建一个powershell脚本,目的是浏览几个git分支,保留了工作更改的补丁,切换到中继线分支以拉远程提交,然后切换回工作分支并重新申请工作更改。
这是我正在专门测试的方法:
git diff > test.patch
git restore .
*do main branch operation*
git apply test.patch
但是,当我尝试应用刚创建的补丁时,我会收到一个错误:
错误:输入中没有有效的补丁(允许使用“ - allow-empty”)
有人看到我在这里做错了什么吗?
GIT版本:2.35.2.Windows.1
PowerShell版本:5.1.19041.1320
I'm creating a powershell script with the goal of going through several git branches, saving a patch of the working changes, switching to the trunk branch to pull remote commits, then switching back to the working branch and reapplying the working changes.
Here is the method I am testing specifically:
git diff > test.patch
git restore .
*do main branch operation*
git apply test.patch
However when I try to apply the patch that I have just created I get an error:
error: No valid patches in input (allow with "--allow-empty")
Does anyone see what I'm doing wrong here?
Git version: 2.35.2.windows.1
Powershell version: 5.1.19041.1320
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
对于其他苦苦挣扎的人 - 我尝试了这一点,但是我也必须以UTF-8格式重新添加补丁文件才能识别它。
For anyone else struggling - I tried this, but I also had to re-save the patch file in UTF-8 format for git to recognise it.
应用补丁时,我也有相同的问题。当我打开补丁程序时,我使用UTF-16 LE BOM编码获得了补丁。这很可能是问题所在。
因此,
您可以使用PowerShell来代替使用PowerShell来创建未保存的更改的补丁(感谢Benf!)
PS。在GIT 2.42中尝试
I have the same problem as well when applying the patch. When I opened the patch, I got the patch with UTF-16 LE BOM encoding. Quite likely this was the problem.
So instead of using
for creating the patch of unsaved changes, using Powershell, you do this instead (thanks benf!)
PS. tried in git 2.42
我也有同样的问题,但是我解决了问题,使用记事本打开补丁文件,在代码选择中选择UTF-8,然后保存它,然后使用git应用程序进入补丁程序
I also had the same problem, but I got it solved, use Notepad to open the patch file, select UTF-8 in the code selection, then save it, and then use git apply patch to enter the patch
在我的情况下,原因是Git配置中的外部DIFF助手设置,因此指定
- No-Ext-Diff
flag帮助In my case the reason was the external diff helper set in git config, so specifying the
--no-ext-diff
flag helpedWindows可能将线路终结器更改为CRLF。让它回到LF。
Likely windows changed the line terminator to CRLF. Get it back to LF.
只需在修补程序文件上运行“ dos2unix your_patch.patch”,就应该在此之后工作。
DOS2Unix应在所有发行版中可用。
Just run "dos2unix your_patch.patch" on your patch file and it should work after.
dos2unix should be available on all distros.