git "revert" 当前目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14125385/
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" current directory
提问by pillarOfLight
In svn it's possible to do svn revert ./*
in which the current directory and ONLY the current directory gets reverted.
在 svn 中,可以svn revert ./*
在其中恢复当前目录并且仅恢复当前目录。
What is the git equivalent to svn revert
in which only the current directory gets reverted?
git 相当于什么svn revert
,其中只有当前目录被恢复?
I know that there's git reset --hard
, but it reverts everything and not just the current directory.
我知道有git reset --hard
,但它会恢复所有内容,而不仅仅是当前目录。
How would I revert just the current directory in git?
我将如何仅恢复 git 中的当前目录?
回答by fge
Like @vcsjones says, the solution here is git checkout
:
就像@vcsjones 说的,这里的解决方案是git checkout
:
git checkout <refspec> -- path/to/directory # or path/to/file
where <refspec>
can, for instance, be HEAD
, that is, the current working commit. Note that this usage of the checkout
command will affect the working tree BUT NOT THE INDEX.
<refspec>
例如,where可以HEAD
是 ,即当前的工作提交。请注意,该checkout
命令的这种用法将影响工作树,但不会影响索引。
git revert
is used to "revert a commit", and by this, it should NOT be understood that the commit disappears from the tree (it would play havoc with history -- if you want that, look at git rebase -i
). A reverted commit consists of applying, in reverse, all changes from the commit given as an argument to the tree and create a new commitwith the changes (with a default commit message, which you can modify).
git revert
用于“恢复提交”,通过这个,不应理解提交从树中消失(它会对历史造成严重破坏——如果你想要,看看git rebase -i
)。还原提交包括反向应用作为参数给出的提交中的所有更改,并使用更改创建新提交(带有默认提交消息,您可以修改)。
回答by Shital Shah
Go to the folder you want to revert and do this:
转到要还原的文件夹并执行以下操作:
git checkout -- .
See more in this answer: https://stackoverflow.com/a/16589534/207661
在此答案中查看更多信息:https: //stackoverflow.com/a/16589534/207661
回答by David Spence
When I was a git novice (and afraid of the terminal) I found the easiest way was to:
当我还是一个 git 新手(并且害怕终端)时,我发现最简单的方法是:
- switch to the branch you want to revert your specific subdirectory to
- copy the subdirectory you want to revert to your desktop
- switch back to your branch
- overwrite the subdirectory you want to replace in your git directory with the one you copied to your desktop
- 切换到您要将特定子目录恢复到的分支
- 复制要恢复到桌面的子目录
- 切换回你的分支
- 用复制到桌面的子目录覆盖 git 目录中要替换的子目录