git revert --no-commit 没有分期
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33674426/
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
git revert --no-commit without staging
提问by lornova
Usually the command git revert
automatically creates some commits with commit log messages stating which commits were reverted.
通常,该命令会git revert
自动创建一些带有提交日志消息的提交,说明哪些提交已被还原。
To avoid automatic commit there's the option -n
(or --no-commit
).
为了避免自动提交,有选项-n
(或--no-commit
)。
But after this command, the reverted files are in the staged area. I can unstage them by using the command git reset HEAD
.
但是执行此命令后,恢复的文件位于暂存区。我可以使用命令取消暂存它们git reset HEAD
。
Is there a direct way to revert a commit without committing and staging?
有没有直接的方法可以在不提交和暂存的情况下恢复提交?
In other words: is there a direct command to revert a commit applying the changes only to the working directory, without touching the index?
换句话说:是否有直接命令来恢复提交,只将更改应用于工作目录,而不触及索引?
采纳答案by torek
There is no single command for it. As you already noted, you can combine git revert -n
with git reset
to get the reversion undone in the index.
没有针对它的单一命令。正如您已经注意到的,您可以结合git revert -n
使用git reset
以在索引中撤消还原。
Besides that method, you can use git apply -R
to "reverse apply" a patch, and you can turn a commit into a patch with git show
, so:
除了该方法,您还可以使用git apply -R
“反向应用”补丁,并且您可以使用 将提交转换为补丁git show
,因此:
$ git show <rev> | git apply -R
has the same effect, with one important (but subtle) difference. Let me quote from the git revert
documentation and add my own emphasis:
具有相同的效果,但有一个重要(但微妙)的区别。让我引用git revert
文档并添加我自己的重点:
-n, --no-commit
Usually the command automatically creates some commits with commit log messages stating which commits were reverted. This flag applies the changes necessary to revert the named commits to your working tree and the index, but does not make the commits. In addition, when this option is used, your index does not have to match the HEAD commit. The revert is done against the beginning state of your index.
-n, --no-commit
通常,该命令会自动创建一些带有提交日志消息的提交,说明哪些提交已被还原。此标志应用将命名提交还原到您的工作树和索引所需的更改,但不进行提交。此外,使用此选项时,您的索引不必与 HEAD 提交匹配。恢复是针对索引的开始状态完成的。
In other words, git revert -n
operates in, and on, the index, with a side effect of updating your work tree. The git apply
command operates (by default anyway) on the work-tree only, and in fact can be used outside a git repository.
换句话说,git revert -n
在 index 中和上操作,具有更新工作树的副作用。该git apply
命令仅在工作树上运行(默认情况下),实际上可以在 git 存储库之外使用。