In Git, how do you see and manage commits that are not on a branch?
The end isn't necessarily in the branch, so how do you see and manage those commits? Also, is it possible to view these commits from gitk?
Thank you so much!
PS: just to make things clearer, here's 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 "unhandled commit" back?
source to share
This situation is called a disabled HEAD . Usually tools (like gitk) will not show you commits that are not available by symbolic branch name.
To get your commit back, you can use git reflog
to display a log of all recent activities, including your highlighted HEAD. When you find it, you can use your commit ID with git checkout
to get back to it. If you find it valuable, you can provide a branch name at this point.
source to share