尝试应用git diff时,错误是“输入中无效的补丁”。

发布于 2025-02-07 00:24:48 字数 414 浏览 3 评论 0原文

我正在创建一个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

月亮邮递员 2025-02-14 00:24:48

很可能Windows将线路终结器更改为CRLF。将其恢复到LF。

对于其他苦苦挣扎的人 - 我尝试了这一点,但是我也必须以UTF-8格式重新添加补丁文件才能识别它。

Likely windows changed the line terminator to CRLF. Get it back to LF.

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.

风和你 2025-02-14 00:24:48

应用补丁时,我也有相同的问题。当我打开补丁程序时,我使用UTF-16 LE BOM编码获得了补丁。这很可能是问题所在。

因此,

# don't do this
git diff > myoldpatch.patch

您可以使用PowerShell来代替使用PowerShell来创建未保存的更改的补丁(感谢Benf!)

git diff | Set-Content -Encoding utf8 .\goodutf8.patch

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

# don't do this
git diff > myoldpatch.patch

for creating the patch of unsaved changes, using Powershell, you do this instead (thanks benf!)

git diff | Set-Content -Encoding utf8 .\goodutf8.patch

PS. tried in git 2.42

笨死的猪 2025-02-14 00:24:48

我也有同样的问题,但是我解决了问题,使用记事本打开补丁文件,在代码选择中选择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

陈年往事 2025-02-14 00:24:48

在我的情况下,原因是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 helped

挽清梦 2025-02-14 00:24:48

Windows可能将线路终结器更改为CRLF。让它回到LF。

Likely windows changed the line terminator to CRLF. Get it back to LF.

深海少女心 2025-02-14 00:24:48

只需在修补程序文件上运行“ 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文