如何在git中的特定哈希值(提交)处签出代码

时间:2020-04-13 08:05:57

标签: git github

我已提交文件,且提交ID(哈希)为1234。 在同一个文件中,我做了很多更改,然后再次提交了一个文件,因此新哈希为567。 我重复此过程,以便新生成的哈希像8910,111213。

我想返回1234版本(与我第一次签入时获得的版本相同)

要采取什么步骤?

2 个答案:

答案 0 :(得分:0)

您可以签出提交哈希,然后根据需要从中创建一个分支。此时,您将与树进行交互。

如果运行git checkout <hash>,则会将树更新到历史记录中的该点。根据您使用的git客户端,您会收到类似

的消息
> git checkout <hash>

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b <new-branch-name>

答案 1 :(得分:0)

# clone repo without initial checkout of HEAD
git clone -n <repo_name>

# checkout specific commit
git checkout 1234

->参见
https://coderwall.com/p/xyuoza/git-cloning-specific-commits
https://guide.freecodecamp.org/git/git-checkout/

相关问题