使用git,如何将工作树(本地文件系统状态)重置为索引状态(“暂存"文件)? [英] Using git, how do you reset the working tree (local file system state) to the state of the index ("staged" files)?

查看:53
本文介绍了使用git,如何将工作树(本地文件系统状态)重置为索引状态(“暂存"文件)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

情况:

  1. 编辑文件
  2. 使用 git add 将文件添加到索引中(这些文件现在已暂存")
  3. 编辑更多文件
  1. Edit files
  2. Add files to the index with git add (these files are now "staged")
  3. Edit more files

现在,我们有三种不同的状态: HEAD 的状态(指向最后的提交),索引的状态(包括所有已添加或暂存"的文件)和工作树的状态(未暂存的本地文件系统状态).撤消工作树中的更改以使其与索引状态匹配的命令是什么?

Now we have three different states: the state of HEAD (which points to the last commit), the state of the index (which includes all added, or "staged" files) and the state of the working tree (the unstaged, local file system state). What is the command to undo changes in the working tree so that it matches the state of the index?

推荐答案

我倾向于使用 git checkout.放弃工作目录中的所有更改.如果您不在存储库的根目录,则会有所不同.

I tend to use git checkout . which discards all changes from the working directory down. This makes a difference if you're not at the root of the repository.

此命令不会删除新创建的文件,这通常是一件好事.如果需要执行此操作,则也可以使用 git clean .

This command doesn't remove newly created files which is usually a good thing. If you need to do this then you can use git clean as well.

这篇关于使用git,如何将工作树(本地文件系统状态)重置为索引状态(“暂存"文件)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆