git撤销文件修改_使用Git撤消文件更改

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.ext
git 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使版本控制变得容易,但是本质上将更改恢复到文件所需的两个步骤并不直观,因此我想我将在此博客上分享。 编码愉快!

翻译自: https://davidwalsh.name/git-undo

git撤销文件修改

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值