在Git中,你如何看待和管理不在分支中的提交? [英] In Git, how do you see and manage commits that aren't in a branch?

查看:104
本文介绍了在Git中,你如何看待和管理不在分支中的提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

提交不一定在分支中,那么您如何看待和管理这些提交?另外,是否有可能从gitk看这些提交?



非常感谢!

PS:just为了让事情更清楚,下面是一个例子:

  git init 
git commit
touch toto
git add toto
git commit -a
echo $ RANDOM> toto
git commit -a
git checkout f798e54 #checkout初始提交
echo $ RANDOM> toto
git commit -a#未跟踪提交
gitk --all
git分支
git log
主分支上的git checkout master #back
gitk --all #untracked提交丢失了?
git log
git branch

如何获得我的未跟踪提交返回?

解决方案

这种情况称为 detailed HEAD 。通常,工具(如gitk)不会向您显示无法通过符号分支名称访问的提交。



要获得提交,可以使用 git reflog 显示所有近期活动的日志,包括您分离的HEAD。当你找到它时,你可以使用它的提交ID和 git checkout 来找回它。如果您发现它很有价值,那么您可能希望在该点给这个分店一个名字。


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?

解决方案

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.

这篇关于在Git中,你如何看待和管理不在分支中的提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆