git 在一行中放弃更改
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6198222/
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
Discard changes in one single line
提问by nacho4d
I've noticed that in Tower (Git client for the Mac) the user can discard changes even line by line. I wonder how could this be done using the command line? or maybe is something special of Tower?
我注意到在 Tower(Mac 的 Git 客户端)中,用户甚至可以逐行丢弃更改。我想知道如何使用命令行完成此操作?或者也许是塔的特别之处?
I frequently find myself in this case:
我经常发现自己处于这种情况:
@@ -391,7 +392,7 @@ extern BOOL validateReceiptAtPath(NSString *path);
NSURL *url = [self fileURL];
if (url != nil) {
NSRect readFrame = [self _readPreferenceOfFileAtURL:url];
-
+
for (NSScreen * screen in [NSScreen screens]) {
NSRect screenVisibleRect = [screen visibleFrame];
...
See how I have one +
and one -
? I would like to discard it so my commit has the minimum changes (hence less possibilities of conflicts and easier review)
看我怎么+
一一-
?我想放弃它,以便我的提交具有最少的更改(因此冲突的可能性较小且更容易)
:)
:)
回答by igorw
This is called interactive stagingand can be done using git add -i
or git add -p
. See the git-add manpage, pro gitand the Git Community Bookfor more information.
这称为交互式登台,可以使用git add -i
或来完成git add -p
。有关更多信息,请参阅git-add 联机帮助页、pro git和Git 社区手册。
EDIT:
编辑:
To interactively unstage a file, you can use:
要以交互方式取消暂存文件,您可以使用:
git checkout -p HEAD
Also see this SO question: Undo part of unstaged changes in git
回答by Robert Siemer
To undo hunks use
要撤消帅哥使用
git reset --patch
It's a very hidden feature. You can stagehunk by hunk with git add --interactive
, but you can't unstagethis way. git add
also features the option --patch
which is like --interactive
, but goes directly to the “patch” menu point (otherwise you have to hit pENTER).
这是一个非常隐蔽的功能。你可以阶段用大块大块git add --interactive
的,但你不能unstage这种方式。git add
还具有--patch
类似的选项--interactive
,但直接进入“补丁”菜单点(否则您必须点击pENTER)。
git reset
does not mirror the --interactive
option, but has --patch
.
git reset
不反映该--interactive
选项,但具有--patch
.
回答by Colin Hebert
You can use git add -e
to edit your file right before staging it.
您可以git add -e
在暂存文件之前使用它来编辑文件。
回答by SamB
You can discard hunks or specific lines with the free program Source Tree.
您可以使用免费程序Source Tree丢弃大块或特定行。
回答by Hrishikesh Kadam
To interactively unstage a file use:
要以交互方式取消暂存文件,请使用:
git add -i
then you will get following options -
然后你会得到以下选项 -
*** Commands ***
1: status 2: update 3: revert 4: add untracked
5: patch 6: diff 7: quit 8: help
Use 3rd option revert
to unstage files
使用第三个选项revert
取消暂存文件
Read more here - https://git-scm.com/book/en/v2/Git-Tools-Interactive-Staging
在这里阅读更多 - https://git-scm.com/book/en/v2/Git-Tools-Interactive-Staging