gpt4 book ai didi

git - 如何中止 git add -p 放弃更改?

转载 作者:行者123 更新时间:2023-12-03 09:26:21 24 4
gpt4 key购买 nike

我在一些文件上运行了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 add -p 暂存更改而不存储历史记录,这可用于恢复添加。但是,您可以使用 git reset -pgit reset --patch 取消暂存更改。程序看起来如下:

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

关于git - 如何中止 git add -p 放弃更改?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20956947/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com