如何在 git 中以交互方式取消暂存特定的大块头?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5188274/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 05:08:37  来源:igfitidea点击:

How do I interactively unstage a particular hunk in git?

gitstaging

提问by Andrew Grimm

In git, if I have a couple of hunks from the same file staged in my index, how can I interactively unstage one of them?

在 git 中,如果我的索引中有来自同一个文件的几个大块头,我如何以交互方式取消其中一个?

Is there any alternative to unstaging the entire file, and then re-staging the hunks I want to keep, or manually undoing the changes to the working copy, and then interactively adding those undone changes?

除了取消暂存整个文件,然后重新暂存我想要保留的大块文件,或者手动撤消对工作副本的更改,然后以交互方式添加那些撤消的更改之外,还有其他选择吗?

回答by Aasmund Eldhuset

Try git reset --patch filename; this should do the opposite of git add --patch, according to the documentation. The short form -palso works for both commands.

尝试git reset --patch filename; git add --patch根据文档,这应该做相反的事情。简短形式-p也适用于这两个命令。

回答by wisbucky

git guihas a decent GUI to interactively stage or unstage hunks or lines. There are prettier/better GUI clients, but git guiis lightweight, built-in, and cross platform (lin, win, mac).

git gui有一个不错的 GUI,可以交互式地上演或取消上演帅哥或台词。有更漂亮/更好的 GUI 客户端,但它们git gui是轻量级、内置和跨平台(lin、win、mac)。

https://git-scm.com/docs/git-gui

https://git-scm.com/docs/git-gui

Simply right click on a hunk to stage/unstage. For lines, highlight the lines first, then right click.

只需右键单击一个大块头即可登台/取消登台。对于线条,首先突出显示线条,然后右键单击。

回答by John Douthat

GitXhas a nice UI for unstaging chunks of a file: enter image description here

GitX有一个很好的用户界面,用于取消文件的分段: 在此处输入图片说明

The official client hasn't been maintained in a while, but a fork over at GitHubwith more features is popular in some circles. (blog post about it)

官方客户端已经有一段时间没有维护了,但是在 GitHub 上的一个具有更多功能的分支在某些圈子中很受欢迎。(关于它的博客文章