在 Git 中,如何查看和管理不在分支中的提交?
提交不一定在分支中,那么如何查看和管理这些提交呢?另外,是否可以从 gitk 查看这些提交?
多谢!
PS:为了让事情更清楚,这里有一个例子:
git init
git commit
touch toto
git add toto
git commit -a
echo $RANDOM > toto
git commit -a
git checkout f798e54 #checkout initial commit
echo $RANDOM > toto
git commit -a #"untracked commit"
gitk --all
git branch
git log
git checkout master #back on the main branch
gitk --all #untracked commit is lost?
git log
git branch
如何找回我的“未跟踪的提交”?
A commit isn't necessarily in a branch, so how do you see and manage these commits? Also, is it possible to look at these commits from gitk?
Thanks a lot!
PS: just to make things clearer, here is an example:
git init
git commit
touch toto
git add toto
git commit -a
echo $RANDOM > toto
git commit -a
git checkout f798e54 #checkout initial commit
echo $RANDOM > toto
git commit -a #"untracked commit"
gitk --all
git branch
git log
git checkout master #back on the main branch
gitk --all #untracked commit is lost?
git log
git branch
How can I get my "untracked commit" back?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这种情况称为分离 HEAD。通常,工具(例如 gitk)不会向您显示无法通过符号分支名称访问的提交。
要取回您的提交,您可以使用
git reflog
显示所有最近活动的日志,包括您分离的 HEAD。当你找到它时,你可以使用它的提交 ID 和 git checkout 来返回它。如果您发现它很有价值,您可能需要在此时为该分支命名。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 withgit 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.您可能在谈论 git fsck --unreachable 吗?
Could it be that you're talking about
git fsck --unreachable
?git reflog
将向您显示一个符号名称,例如HEAD@{0}
,您可以使用它来访问原本无法访问的提交。然后,您可以使用 gitk --all HEAD@{0} 来查看它在存储库中的位置。git reflog
will show you a symbolic name likeHEAD@{0}
that you can use to access that otherwise unreachable commit. You could then usegitk --all HEAD@{0}
to see where it exists in your repository.