git reset --hard HEAD和git checkout之间有区别吗? [英] Is there a difference between git reset --hard HEAD and git checkout .?

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

问题描述

如果我对工作树进行了更改并且尚未提交,并且我想恢复所做的更改,那么

<$ p $ git reset --hard HEAD

  git checkout。 

解决方案 git checkout - 。显然只适用于当前目录(及其子目录), git reset --hard code>将在完整的工作树上运行。



git checkout - 。工作树并保留已经登台的文件,而 git reset --hard 将使索引和工作树与HEAD提交匹配。



与refspec一起使用时:


  1. reset 会设置当前分支头到给定的提交(并匹配索引和工作树)
  2. checkout 将切换到该分支,使本地更改保持原样,当他们触摸当前分支和要检出的分支之间没有变化的文件时


If I make changes to the working tree and have not yet committed, and I would like to revert the changes I have made, is there a difference between

git reset --hard HEAD

and

git checkout .

?

解决方案

git checkout -- . will obviously only work on the current directory (and subdirectories thereof), git reset --hard will operate on the complete working tree.

git checkout -- . will only update the working tree and leave already staged files as is, whereas git reset --hard will match index and working tree with the HEAD commit.

when used with a refspec:

  1. reset will set the current branch head to the given commit (and matches index and working tree)
  2. checkout will switch to that branch, leaving local changes intact, when they touch files which did not change between the current branch and the branch to be checked out

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

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