简体   繁体   English

“git reset --hard”和“git checkout”有什么区别?

[英]What is the difference between “git reset --hard” and “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 .

This tells Git to checkout the current folder, whatever that is, from the current branch and replace the working folder with it. 这告诉Git从当前分支中检出当前文件夹,并用它替换工作文件夹。 But this does not affect other areas of the working folder, nor does it involve the stage. 但这不会影响工作文件夹的其他区域,也不会影响舞台。

git reset --hard

This resets the entire working directory and stage to the HEAD of the current branch. 这会将整个工作目录阶段重置为当前分支的HEAD。 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. 一般来说硬重置是你不经常使用的东西,而从各个地方检出文件/文件夹更常见。

There are same if you don't follow them with any commit id ie they resets your state to the latest commit. 如果您没有使用任何提交ID,那么它们也是相同的,即它们将您的状态重置为最新提交。 However if you do reset --hard <commit_id> , it changes the HEAD of your current branch to commit id specified, whereas checkout creates a temporary branch. 但是,如果您reset --hard <commit_id> ,它会将当前分支的HEAD更改为指定的提交ID,而checkout会创建临时分支。

git checkout 6a0ff74 
# would create a temp branch with its HEAD pointed to commit id
# you can just checkout your original branch.

git reset --head 6a0ff74
# would change the `HEAD` of the current branch. To reverse the change
# you must find the latest commit id and `reset --hard` to it again.

git checkout get update data from Git server, also keep your change at local machine. git checkout从Git服务器获取更新数据,同时保持对本地计算机的更改。

git reset --hard make a copy identity like Git server at a specific HEAD, and discard all change at your local machine. git reset --hard在特定的HEAD上创建Git服务器的复制标识,并丢弃本地计算机上的所有更改。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “git checkout — .” 和有什么区别? 和“git reset HEAD --hard”? - What is the difference between “git checkout — .” and “git reset HEAD --hard”? git checkout和有什么不一样? vs git reset --hard HEAD - What is the difference between git checkout . vs git reset --hard HEAD “git checkout -f”和“git reset --hard HEAD”有什么区别? - What is difference between “git checkout -f” and “git reset --hard HEAD”? git reset - hard和git checkout之间的区别 - Difference between git reset --hard and git checkout git reset - hard HEAD和git checkout之间有区别吗? - Is there a difference between git reset --hard HEAD and git checkout .? “git reset --hard hash”和“git checkout hash”之间有区别吗? - Is there a difference between “git reset --hard hash” and “git checkout hash”? git checkout HEAD -- 之间有区别吗? 和 git reset --hard HEAD? - Is there a difference between git checkout HEAD -- . and git reset --hard HEAD? git reset --hard 之间的区别<filename>和 git checkout --<filename> - Difference between git reset --hard <filename> and git checkout -- <filename> git reset --hard 和 git reset --merge 有什么区别 - What's the difference between git reset --hard and git reset --merge git reset –hard head`和`git clean –force -d`vs`git checkout —之间有什么区别,以放弃本地更改。 - What is the difference between `git reset --hard head` vs `git clean --force -d ` vs `git checkout — .` to discard local changes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM