git - 手动编辑 git add --patch 导致错误(补丁失败)

标签 git

我有这个大块头,我想对其进行编辑,以便忽略对 uuid 的更改。

# Manual hunk edit mode -- see bottom for a quick guide.
@@ -43,4 +44,7 @@
        "date-fns": "^2.23.0",
-       "uuid": "^8.3.2"
+       "imask": "^6.1.0",
+       "uuid": "^8.3.2",
+       "validator": "^13.6.0",
+       "vest": "^3.2.5"
    }
 }
# ---
# To remove '-' lines, make them ' ' lines (context).
# To remove '+' lines, delete them.
# Lines starting with # will be removed.

到目前为止,我的想法是执行以下操作,这意味着 hunk header 不需要更改(对吧?)。

# Manual hunk edit mode -- see bottom for a quick guide.
@@ -43,4 +44,7 @@
        "date-fns": "^2.23.0",
        "uuid": "^8.3.2"
+       "imask": "^6.1.0",
+       "validator": "^13.6.0",
+       "vest": "^3.2.5"
    }
 }
# ---
# To remove '-' lines, make them ' ' lines (context).
# To remove '+' lines, delete them.
# Lines starting with # will be removed.

但是,保存更改并退出后,我仍然得到以下信息:

error: patch failed: package.json:43
error: package.json: patch does not apply

在这一点上,我很困惑,我不确定要尝试什么。起初我以为是缺少空格,因为我的 VIM 配置用制表符替换了它,但手动添加空格也不能解决问题(在 - 行中)。

到目前为止,我唯一的猜测是标题有问题,但它应该正确排列,对吗?我仍然在这两种情况下添加 7 行,4 保持不变。

我已经查看了 similar questions但还没有找到解决此类问题的方法。

我可以尝试使用 GUI,但我想尽可能避免使用它。

有什么想法吗?我将不胜感激。

最佳答案

看来您遇到了与 this other user 相同的问题: 如果你在 git add -p 中拆分一个大块,有一个错误会阻止应用“手动编辑”一个子大块。

解决方法很简单:搁置当前版本的 package.json,然后将该文件编辑为您要提交的版本。

同样值得注意的是:git gui 提供了一个功能完美的“stage this line”操作——当您右键单击右侧 Pane 中显示的 diff 中的任何行时。

关于git - 手动编辑 git add --patch 导致错误(补丁失败),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69078859/

相关文章:

git - 如何使用 git clone --depth 1 check out 远程分支?

php - Git使用私钥从带有shell_exec的PHP文件中获取

node.js - 使用 simple-git 进行 Nodejs 浅 git 克隆

git - 查找与文件特定部分相关的 git 提交

git - 如何使用和理解 wso2 git 存储库?

带有 `post-receive` 的 Git Hook `git pull` 通过命令行运行良好但在自动 Hook 时返回空字符串

Git Checkout 与 git bash 一起无限期挂起。怎么解决?

php - mysql 的凭据应该放在哪里?

git - 如何将文件目录添加到一组已推送的提交中?

svn - Git 对比 Mercurial 对比 SVN