In Git, how do you see and manage commits that aren't in a branch?

蓝咒 提交于 2019-12-02 00:30:49

This situation is called a detached HEAD. Normally tools (such as gitk) won't show you commits that aren't reachable by a symbolic branch name.

To get your commit back, you can use git reflog to show a log of all recent activity, including your detached HEAD. When you find it, you can use its commit ID with git checkout to get back to it. If you find that it's valuable, you may want to give the branch a name at that point.

Could it be that you're talking about git fsck --unreachable?

git reflog will show you a symbolic name like HEAD@{0} that you can use to access that otherwise unreachable commit. You could then use gitk --all HEAD@{0} to see where it exists in your repository.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!