gpt4 book ai didi

git - 交互式撤消本地更改

转载 作者:太空狗 更新时间:2023-10-29 13:22:12 25 4
gpt4 key购买 nike

我经常在开发时添加一些调试代码,所以我需要稍后删除这些更改。

目前,我检查 git diff 并手动删除更改,或者如果我想撤消整个文件,则只需键入 git checkout -- myfilename

我喜欢交互式补丁功能(git add -i)。 git 中是否有工具或命令可以撤消交互式更改,例如 git add -i

换句话说:我想以交互方式 check out 索引中的文件和 block 。

最佳答案

你要找的命令是

$git checkout -p

git checkout Manual Page说:

-p

--patch

Interactively select hunks in the difference between the (or the index, if unspecified) and the working tree. The chosen hunks are then applied in reverse to the working tree (and if a was specified, the index).

This means that you can use git checkout -p to selectively discard edits from your current working tree. See the “Interactive Mode” section of git-add(1) to learn how to operate the --patch mode.


如果您想以交互方式恢复阶段性更改,请使用 git reset --patchgit reset -p

来自 the docs :

git reset (--patch | -p) [] [--] [...]

Interactively select hunks in the difference between the index and (defaults to HEAD). The chosen hunks are applied in reverse to the index.

This means that git reset -p is the opposite of git add -p, i.e. you can use it to selectively reset hunks. See the “Interactive Mode” section of git-add(1) to learn how to operate the --patch mode.

关于 git add -p it says

-p

Interactively choose hunks of patch between the index and the work tree and add them to the index. This gives the user a chance to review the difference before adding modified contents to the index.

This effectively runs add --interactive, but bypasses the initial command menu and directly jumps to the patch subcommand. See “Interactive mode” for details.

所以基本上使用 git reset -p 你可以选择你重置的内容。

关于git - 交互式撤消本地更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23295986/

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