views:

95

answers:

3

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?

+2  A: 

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.

Bombe
+3  A: 

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

Michael Krelin - hacker
+5  A: 

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.

Greg Hewgill
Thanks a lot for your detailed answer! I've discovered a whole area of git that I didn't know of :)thanks also to "hacker" for mentioning git fsck.
static_rtti
You don't need commit ID to get back on branch: `git checkout -b newbranch` would be enough.
Jakub Narębski