交互撤消本地更改

编程入门 行业动态 更新时间:2024-10-10 05:19:33
本文介绍了交互撤消本地更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

我喜欢交互式补丁函数( git加-i )。在git中是否有一个工具或命令可以撤销交互变化,如 git add -i ?

其他词:我想交互式地检出文件和hunk出索引。

解决方案

你在找什么我认为是 git reset --patch 或 git reset -p

从文档:

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

在索引和(默认为HEAD)之间的差异中交互选择hunk。所选的hunks被反向应用于索引。

这意味着git reset -p与git add -p相反,也就是说可以使用它来选择性地重置帅哥。请参阅git-add(1)的交互模式部分,了解如何操作--patch模式。

以及about git add -p 它表示

-p

索引和工作树之间的补丁并将它们添加到索引。这使用户有机会在将修改内容添加到索引之前查看差异。

这有效地运行了add -interactive ,但绕过初始命令菜单并直接跳转到patch子命令。

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

编辑: b

正如 git checkout手册页所述:

-p

补丁

交互式地选择区别(或索引,如果未指定)和工作树之间的区块。然后选择的hunk被反向应用到工作树(如果指定了a,索引)。

这意味着你可以使用git checkout -p来选择从当前工作树中删除编辑。请参阅git-add(1)的交互模式部分,了解如何操作--patch模式。

您正在寻找的命令是

$ git checkout -p

I often add some debug code while developing so I need to remove these changes later.

Currently, I check the git diff and remove the changes manually or just type git checkout -- myfilename if I would like to undo the entire file.

I love the interactive patch function (git add -i). Is there a tool or a command in git which can undo changes interactive like git add -i?

In other words: I would like to interactively checkout files and hunks out of the index.

解决方案

What you are looking for I think is git reset --patch or git reset -p

From 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.

and about 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.

So basically with git reset -p you can select what you reset.

Edit:

As the git checkout Manual Page mentions:

-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.

So the command you are looking for is

$git checkout -p

更多推荐

交互撤消本地更改

本文发布于:2023-11-09 07:49:32,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!