git Magit 还原单个文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17131690/
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
Magit revert single file
提问by Rémi
The question is about Magit major mode for Emacs function and less so about how to do this via command line interface.
问题是关于 Emacs 功能的 Magit 主要模式,而不是关于如何通过命令行界面执行此操作的问题。
I only have a local Git repository. How would I restore a selected file to its previous version? I believe that the Git command for this must be something like git checkout HEAD^ path/to/file
but I may be wrong here too, just guessing really.
我只有一个本地 Git 存储库。如何将选定的文件恢复到以前的版本?我相信用于此的 Git 命令一定是类似的,git checkout HEAD^ path/to/file
但我在这里也可能错了,只是猜测。
What I'm looking for is essentially the same thing as C-x v uin vc-dir
buffer.
我正在寻找本质上是一样的东西C-x v u在vc-dir
缓存。
Essentially, what I was hoping to do was:
基本上,我希望做的是:
delete the modified file.
pull from local repo.
删除修改后的文件。
从本地仓库拉取。
But Magitdoesn't seem to be able to do that, it seems to prefer to just delete the file, instead of restoring it.
但是Magit似乎无法做到这一点,它似乎更喜欢删除文件,而不是恢复它。
回答by Rémi
In magit you just have to go on the hunk or file you want to revert, and use k
to discard a modification. See the relevant documentation at https://magit.vc/manual/1.4/magit/Staging-and-Committing.htmlfor more detail.
在 magit 中,您只需要继续处理要还原的大块或文件,并使用它k
来放弃修改。有关更多详细信息,请参阅https://magit.vc/manual/1.4/magit/Staging-and-Committing.html 上的相关文档。
回答by Razzi Abuissa
With the file open, you can M-x magit-file-checkout
.
打开文件后,您可以M-x magit-file-checkout
.