交互撤消本地更改 [英] Undo local changes interactive

查看:128
本文介绍了交互撤消本地更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



目前,我检查 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

这篇关于交互撤消本地更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆