简体   繁体   English

如何从git中的提交历史转到提交?

[英]how to go to a commit from history of commits in git?

I deleted one file after my first commit, and I want to know how can I revert back to that commit state (all files in working dir to that state). 我第一次提交后删除了一个文件,我想知道如何恢复到该提交状态(工作目录中的所有文件都返回到该状态)。 Can someone please help me with this? 有人可以帮我吗?

$ git log
commit 2e8bd07a1f7446d2acef86f854ad57dabe4e5834
Author: Sam <sam@mysite.com>
Date:   Sun Aug 21 00:21:12 2016 +030

    baseline

g@DESKTOP MINGW64 /c/mydir (master)

You can use : 您可以使用 :

$ git log

and then checkout the commit : 然后签出提交:

$ git checkout 2e8bd07a1f7446d2acef86f854ad57dabe4e5834

You can use git checkout FILE to revert a file in the working directory back to its committed state. 您可以使用git checkout FILE将工作目录中的文件恢复为已提交状态。 This also works for whole directories, so git checkout . 这也适用于整个目录,因此git checkout . will recursively revert all files in the current directory. 将递归还原当前目录中的所有文件。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM