使用git,你如何重置工作树到索引的状态? [英] Using git, how do you reset the working tree to the state of the index?

查看:516
本文介绍了使用git,你如何重置工作树到索引的状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

情况:

Situation:


  1. 编辑文件

  2. 将文件添加到索引

  3. 编辑更多文件

现在我们有三种不同的状态。 HEAD的状态,索引状态和工作树的状态。什么是撤消在工作树中的变化,以便它匹配的索引状态的命令是什么?

Now we have three different states. The state of HEAD, the state of the index and the state of the working tree. 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天全站免登陆