git - 如何转到git中的特定提交

标签 git github git-commit

我已经在git中提交了,我想转到第二次提交。我已经使用了

git checkout <commit id>

commit 3f54a651504adc885a71db275e0fb4a5a1111cf4 (HEAD -> dev_coder, origin/dev_coder)
Author: Coder <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="274448434255674a420944484a" rel="noreferrer noopener nofollow">[email protected]</a>>
Date:   Sun Jun 27 20:23:48 2021 +0530

   button 

commit 362d11072139bda8569dcf37012174258e8078c3
Author: Coder <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="690a060d0c1b29040c470a0604" rel="noreferrer noopener nofollow">[email protected]</a>>
Date:   Fri Jun 25 14:30:01 2021 +0530

    updated owner

commit 0db31695b550748c27486248974ee6f57c88458
Author: Coder <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b8dbd7dcddcaf8d5dd96dbd7d5" rel="noreferrer noopener nofollow">[email protected]</a>>
Date:   Wed Jun 16 21:25:28 2021 +0530

    Added  field

commit 2c72f1ef0bd6a6e7da785212a05efa08a308f1fa
Author: Coder <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4f2c202b2a3d0f222a612c2022" rel="noreferrer noopener nofollow">[email protected]</a>>
Date:   Fri Jun 11 10:36:01 2021 +0530

我在一个名为 dev_coder 的分支中,而不是在主分支中。我想转到 362d11072139bda8569dcf37012174258e8078c3 提交。当我使用下面的分支时,它会更改分支并显示其他内容。

git chekout 362d11072139bda8569dcf37012174258e8078c3

最佳答案

您的问题标题是:“如何转到 git 中的特定提交”,实际上,您已经实现了:git checkout 362d110 会将您的存储库设置为该提交中的状态。

但是,输入直接提交哈希作为目标也会将您的存储库设置为所谓的“分离 HEAD”状态,如果您是 git 新手,这可能会令人不安。

如果您的目的是从那里开始创建一个新分支,您可以创建一个分支,并指示 git 将其用作事件分支:

git branch my-work
git checkout my-work
# you will now be working on a branch named 'my-work'

实际上有一个快捷方式可以在一个命令中执行此操作:

git checkout -b my-work

关于git - 如何转到git中的特定提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69222372/

相关文章:

node.js - 维护单独的 git 分支 - 一个用于 heroku,另一个用于 github

svn - 如何通过SVN访问GitHub(Dreamweaver CS6)

git - 我已经更新了 Git 和 'lost my Head' ,所以现在我无法提交

git:只保留特定文件的最新版本

github - $ git commit --amend 不改变/保存提交信息

git - 跟踪忽略目录中的文件

GIT "stop tracking"无法使用源代码树

GitHub 错误 - "ssh: connect to host github.com port 22: Operation timed out fatal: Could not read from remote repository."

没有提交的 Git checkout 分支

git - 我怎样才能从 git 中删除分离的提交?