"git reset --hard"和"git reset --hard"有什么区别?和"git checkout". [英] What is the difference between "git reset --hard" and "git checkout ."?

查看:121
本文介绍了"git reset --hard"和"git reset --hard"有什么区别?和"git checkout".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我要在项目中进行某些更改并且想要返回上一次提交的状态时,可以同时使用这两个选项.他们实际上是在做同样的事情,还是它们之间有什么区别?

When I want some changes in my project and I want to return to the state of the last commit, I can use these both options. Do they actually do the same thing or is there any difference between them?

推荐答案

这是两个命令之间的区别:

Here is the difference between the two commands:

git checkout .

这告诉Git从当前分支中签出当前文件夹(无论是什么),并用它替换 working 文件夹.但这不会影响工作文件夹的其他区域,也不会涉及该阶段.

This tells Git to checkout the current folder, whatever that is, from the current branch and replace the working folder with it. But this does not affect other areas of the working folder, nor does it involve the stage.

git reset --hard

这会将整个工作目录阶段重置为当前分支的HEAD.您可以认为这有效地抑制了自从上一次提交以来发生的所有事情.

This resets the entire working directory and stage to the HEAD of the current branch. You can think of this as effectively nuking everything which has happened since your last commit.

通常来说,硬重置是您不常使用的东西,而从不同位置签出文件/文件夹则更为常见.

Generally speaking hard reset is something you won't use that often, whereas checking out files/folders from various places is more common.

这篇关于"git reset --hard"和"git reset --hard"有什么区别?和"git checkout".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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