【问题标题】:What's the point of "edit" option in `git reset --patch"`git reset --patch" 中的“编辑”选项有什么意义
【发布时间】:2019-11-19 10:15:36
【问题描述】:

git reset -p 的用例是什么,然后在重置之前使用“e”选项编辑应用的块?

我尝试使用该命令,但我尝试的所有编辑都被 git 拒绝。

【问题讨论】:

  • 如果您收到“your-edited-hunk-does-not-apply”错误,那么这篇文章很有帮助/相关:stackoverflow.com/questions/3268596/…
  • 在编辑e 时必须非常小心,以便仅将- 替换为空格或将行删除为+。然后我发现即使我很小心,更改最后一行有时也会让 Git 不高兴。但是一旦成功,Git 会将结果放入缓存中,准备提交将事物恢复到选定状态。我发现令人困惑的是,这只会更改缓存,但不会更改工作目录。
  • 用例,正如您已经发现的那样,是在应用之前编辑大块。

标签: git git-reset


【解决方案1】:

我认为手册页解释了用例,以及您遇到的常见陷阱(为格式化而编辑):

-e, --edit
       Open the diff vs. the index in an editor and let the user edit it.
       After the editor was closed, adjust the hunk headers and apply the patch
       to the index.

       The intent of this option is to pick and choose lines of the patch to
       apply, or even to modify the contents of lines to be staged. This can be
       quicker and more flexible than using the interactive hunk selector.
       However, it is easy to confuse oneself and create a patch that does not
       apply to the index. See EDITING PATCHES below.

我见过人们有效地使用这个命令;它非常适合删除多余的行和空格、记录器和调试器语句,或者修复最后一分钟的拼写错误。但应谨慎使用,因为很容易创建不适用的补丁。

发生这种情况时,您可以使用 n 放弃更改并在文本编辑器中进行正确的更改。

请参阅man git-add 了解更多信息。

【讨论】:

    猜你喜欢
    • 2021-07-04
    • 1970-01-01
    • 2020-06-22
    • 2013-03-04
    • 2019-08-30
    • 1970-01-01
    • 2012-06-28
    • 2011-04-08
    • 2015-01-17
    相关资源
    最近更新 更多