[英]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.