English 中文(简体)
放弃单行中的更改
原标题:Discard changes in one single line
  • 时间:2011-06-01 08:21:12
  •  标签:
  • git

我注意到,在Tower(Mac的Git客户端)中,用户甚至可以逐行丢弃更改。我想知道如何使用命令行来完成这项工作?或者Tower有什么特别之处?

我经常发现自己处于这种情况:

@@ -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];
                        ...

看看我如何拥有一个+和一个-?我想放弃它,这样我的承诺就有最小的变化(因此冲突的可能性更小,审查更容易)

:)

最佳回答

这被称为交互式暂存,可以使用git add-igit add-p来完成。请参阅git add手册页按数字Git社区书了解更多信息。

编辑:

要以交互方式取消暂存文件,可以使用:

git checkout -p HEAD

另请参阅此SO问题:撤消git中未记录的部分更改

问题回答

要撤消大块,请使用

git reset --patch

这是一个非常隐蔽的特征。您可以用git-add一个接一个地执行,交互式,但您不能用这种方式取消执行git-add还提供了选项--patch,这与--interactive类似,但直接进入“patch”菜单点(否则您必须点击pENTER)。

git reset不镜像--交互式选项,但具有--patch

您可以使用<code>git add-e</code>在暂存文件之前对其进行编辑。

要以交互方式取消暂存文件,请使用:

git add -i

然后您将获得以下选项-

*** Commands ***
  1: status       2: update       3: revert       4: add untracked
  5: patch        6: diff         7: quit         8: help

使用第三个选项revert来取消暂存文件

点击此处阅读更多信息-https://git-scm.com/book/en/v2/Git-Tools-Interactive-Staging





相关问题
git confusion - cloning a repo is returning a past version

Im having some confusion with my git usage. I cloned a repo from one comp to the other, and the new clone is the state of the original that was active some time ago. So its cloning a past version. ...

Appropriate strategy for tagging and hotfixing with git

I was wondering if the strategy I m using for tagging and hotfixing tags (which then I use for deploying rails applications) with git is appropriate. For tagging I just tag a commit of the master ...

Tips on upgrading CVS to git/hg?

We still use CVS, I use git and hg for my personal use though I m still a novice at both, but I realize they re much more modern and better, faster, distributed, etc. It s just everyone is so ...

Using Git in a TFS shop

Using Git at home has spoiled me - I now find using TFS at work to be a bit of a drag and want to explore the possibility of using Git locally and syncing somehow with TFS. I figure there are a few ...