如何撤销对特定文件的本地更改 [英] How to undo local changes to a specific file
问题描述
我试图撤销对特定文件的本地更改。没有提交任何内容。
当我想恢复所有更改时,我可以执行 git revert --reset HEAD
。但是,在这种情况下,我不想恢复所有文件的所有更改。
对于我来说,如何还原文件阅读 git-revert(3)
手册页:
NAME
git-revert - 还原一些现有的提交
概要
git还原[ - [no-]编辑] [-n] [-m父编号] [-s] < commit> ...
git revert --continue
git revert --quit
git revert --abort
...
这与如何恢复某个特定文件旧的提交git ,但没有提交已执行。与OP不同,谁想要回到任意提交,我只想让文件返回MASTER的副本。
在SVN下,我只是删除文件,然后执行 svn update
。
如何将更改恢复为单个文件? p>
您不希望 git revert
。这解除了以前的提交。你需要 git checkout
来从master获得git的文件版本。
git checkout - filename.txt
一般来说,当你想对单个文件执行git操作时,使用 - 文件名
。
I'm trying to undo local changes to a specific file. Nothing has been committed.
When I want to revert all changes, I can perform git revert --reset HEAD
. However, in this case, I don't want to revert all changes to all files.
Its not clear or obvious to me how to revert just a file, even after reading the git-revert(3)
man page:
NAME
git-revert - Revert some existing commits
SYNOPSIS
git revert [--[no-]edit] [-n] [-m parent-number] [-s] <commit>...
git revert --continue
git revert --quit
git revert --abort
...
This is similar to How to revert a specific file in a old commit on git, but no commits have been performed. And unlike OP, who wants to go back to an arbitrary commit, I just want the file to return to MASTER's copy of it.
Under SVN, I would just delete the file in question and then perform a svn update
.
How do I revert changes to a single file?
You don't want git revert
. That undoes a previous commit. You want git checkout
to get git's version of the file from master.
git checkout -- filename.txt
In general, when you want to perform a git operation on a single file, use -- filename
.
这篇关于如何撤销对特定文件的本地更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!