从本地计算机恢复 git 最新提交

restore git latest commit from local computer

我在本地计算机上创建了我的代码。

一旦我将代码推送到 git 服务器。

git add -A
git commit -m "test"
git push -u ...

之后我在同一个分支上做了很多修改,然后提交

git add -A
git commit -m "test"

提交成功,但我没有推送,而是做了

git checkout master

然后我意识到我没有推送代码,所以我推送了

git checkout mybranch

我再次意识到我所做的检查是从git服务器上进行的,我没有看到我的代码,即使我提交了。

我知道提交保留在我的本地计算机上,但我最近的更改消失了吗?

如何恢复我的最新更改?

先谢谢你。

您应该能够 git switch (better than git checkout) 您的分支并查看您的代码。

但如果没有,请检查 git reflog,并查找最近的提交 SHA:尝试 git switch --detach <SHA> 检查该提交,确保您的更改在那里。

OP Eitan reports in having succeeded, using git log --pretty:

I found the date+time, and do checkout.

 git reflog --pretty=format:"%H %an %ad"