git - 如何在 git 中的特定哈希(提交)处 checkout 代码

标签 git github

我已经提交了一个文件,提交 ID(哈希值)是 1234。 在同一个文件中,我做了很多更改,并再次提交了一个文件,因此新的哈希值是 567。 我重复这个过程,所以新生成的哈希值就像 8910,111213。

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

具体步骤是什么?

最佳答案

您可以 checkout 提交哈希,然后根据需要从中创建分支。您将在历史记录的那个时刻与树进行交互。

如果你运行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>

关于git - 如何在 git 中的特定哈希(提交)处 checkout 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61183772/

相关文章:

Github 权限

github - 在 GitHub wiki 中搜索关键字

python - 在 Github 托管站点中嵌入交互式 Bokeh 或 Plotly 图形

git - 在 IntelliJ 项目中更改在线 git 存储库 url

windows - 如何处理在 Linux 上使用无效 Windows 文件名提交给 Git 的文件?

python - 在父项目上运行 pytest 时,如何忽略 git 子模块根目录下的 conftest.py 文件(例如 submodule/conftest.py)?

github - 查找库的最新构建版本

linux - 错误 : RROR] Process or Namespace not found. PM2 错误 Linux 服务器与 github 操作

git - 将忽略的配置文件作为示例添加到 git repo

bash - 检查 git 分支是否包含给定主题的提交