【问题标题】:How to abort git add -p discarding changes?如何中止 git add -p 丢弃更改?
【发布时间】:2014-01-24 06:27:18
【问题描述】:

我在一些文件上运行了git add,构成了一组独立的逻辑更改,对它们进行了其他更改,并使用git add -p提取了另一组逻辑更改。进行到一半,我意识到我还没有提交上一组。

git add -p 的交互式帮助仅提供以下选项:

Stage this hunk [y,n,q,a,d,/,s,e,?]? ?
y - stage this hunk
n - do not stage this hunk
q - quit; do not stage this hunk nor any of the remaining ones
a - stage this hunk and all later hunks in the file
d - do not stage this hunk nor any of the later hunks in the file
g - select a hunk to go to
/ - search for a hunk matching the given regex
j - leave this hunk undecided, see next undecided hunk
J - leave this hunk undecided, see next hunk
k - leave this hunk undecided, see previous undecided hunk
K - leave this hunk undecided, see previous hunk
s - split the current hunk into smaller hunks
e - manually edit the current hunk
? - print help

如何重置添加的补丁?

【问题讨论】:

    标签: git git-reset git-add


    【解决方案1】:

    git add -p 阶段更改而不存储历史记录,可用于恢复添加。但是,您可以使用 git reset -pgit reset --patch 取消暂存更改。一个过程将如下所示:

    • 输入q
      退出互动git add -p
    • git reset -p
      重置所有错误添加的更改
    • git commit
      提交第一个变更集
    • git add -p
      再次向新的第二次提交添加更改
    • git commit
      提交第二次提交

    【讨论】:

      猜你喜欢
      • 2015-03-08
      • 2020-06-01
      • 2016-10-28
      • 1970-01-01
      相关资源
      最近更新 更多