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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 08:39:10  来源:igfitidea点击:

Magit revert single file

gitemacsmagit

提问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/filebut 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-dirbuffer.

我正在寻找本质上是一样的东西C-x v uvc-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 kto 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.