git撤销文件修改
One of my favorite features in modern text editors is their ability to integrate tools to format code upon every save. When you're working on legacy projects, however, auto-formatting can be a problem; if you open a file that you don't explicitly change, the file may still get modified by the formatter. This all leads to git status
showing a bunch of file modifications that you don't want.
现代文本编辑器中我最喜欢的功能之一是它们能够集成工具以在每次保存时格式化代码。 但是,当您处理旧项目时,自动格式化可能会成为问题。 如果打开的文件没有明确更改,则格式化程序可能仍会对该文件进行修改。 所有这些都会导致git status
显示一堆您不需要的文件修改。
To quickly undo file changes with git, execute the following two commands:
要使用git快速撤消文件更改,请执行以下两个命令:
git reset HEAD path/to/file.extgit checkout path/to/file.ext
The second command (checkout
) is required or you'll still see the file listed when running git status
again. With both of those executions, you'll no longer see the file listed with git status
.
第二个命令( checkout
)是必需的,否则当再次运行git status
时,您仍然会看到列出的文件。 通过这两个执行,您将不再看到带有git status
列出的文件。
git makes version control easy but the two steps needed to essentially revert changes to a file aren't intuitive, thus I thought I would share on this blog. Happy coding!
git使版本控制变得容易,但是本质上将更改恢复到文件所需的两个步骤并不直观,因此我想我将在此博客上分享。 编码愉快!
翻译自:
git撤销文件修改