gpt4 book ai didi

git - 在我使用 git reset 转到较旧的变更集后,如何返回到历史记录中的最后一次提交?

转载 作者:IT王子 更新时间:2023-10-29 01:30:11 25 4
gpt4 key购买 nike

假设我的历史是这样的:

A - B - C - D(大师)

如果我执行 git reset B,我会得到:

A - B(主)

问题是,git log 现在只显示从 A 到 B 的历史记录,我再也看不到 C 和 D。

我怎样才能回到D?

最佳答案

您应该能够通过 git reflog 看到 D .

查看此 article for instance .

The only time commits are actually deleted is if you git gc --prune (so be careful with that one!).

If you run git reflog right now in a repository you’ve been working in, you’ll see lots of changes that look something like this:

c5c3a82... HEAD@{0}: pull origin featureB: Merge made by recursive.
49d0608... HEAD@{1}: reset --hard HEAD^: updating HEAD
3ed01b1... HEAD@{2}: pull origin featureA: Merge made by recursive.
49d0608... HEAD@{3}: pull origin bugfixJ: Merge made by recursive.
854d44e... HEAD@{4}: commit: Add more cowbell to foo.c
6dbc22d... HEAD@{5}: pull origin bugfixI: Merge made by recursive.
9bdb763... HEAD@{6}: commit: Remove weevils
8518f9d... HEAD@{7}: checkout: moving from wickedfeature to master

These lines can be broken down into 4 parts:

  • commit hash,
  • commit pointer,
  • action,
  • and extra info.

If we wanted to get back the commit that was lost at HEAD@{1}, we could just git reset --hard HEAD@{2}.
Now our current branch (and working copy) are set to the repository state before we did the reset.

If we wanted to just see what that state was, we could git checkout -b temp HEAD@{2} (or git checkout HEAD@{2} if you have git 1.5.0 and up).

关于git - 在我使用 git reset 转到较旧的变更集后,如何返回到历史记录中的最后一次提交?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2540505/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com