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?

+2


source to share


3 answers


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.

+8


source


Maybe you are talking about git fsck --unreachable

?



+3


source


git reflog

will show you a symbolic name, for example HEAD@{0}

, which you can use to access that unreachable commit. Then you can use gitk --all HEAD@{0}

to find out where it exists in your repository.

+2


source







All Articles