Let's say that I have a graph like this:
A---B---C---D (master)
\
\-E---F (HEAD)
If I do git log --all --oneline
, I will get all six of my commits.
But if the graph is
A---B---C---D (master, HEAD)
\
\-E---F
I will not see E and F. Can I get git to tell me all the commits, including those on branches which are not named?
Thanks
What saved my life was the following command:
There you find a screen with history commits done to git like this one:
At this point, you only have to find the
HEAD@{X}
that you need, create a temporary branch and move to it like this:That way you will have a temporary branch with your lost commit without rebasing or breaking even more your git repository.
Hope this helps...
Not particularly easily- if you've lost the pointer to the tip of a branch, it's rather like finding a needle in a haystack. You can find all the commits that don't appear to be referenced any more-
git fsck --unreachable
will do this for you- but that will include commits that you threw away after agit commit --amend
, old commits on branches that you rebased etc etc. So seeing all these commits at once is quite likely far too much information to wade through.So the flippant answer is, don't lose track of things you're interested in. More seriously, the reflogs will hold references to all the commits you've used for the last 60 days or so by default. More importantly, they will give some context about what those commits are.
@bsimmons
Then create a branch for each one:
Now many tools will show you a graphical visualization of those lost commits.
How I solve this problem? Use
git fsck
and logging!First create a file containing lost (unreachable) commits and blobs. (NOTE: if you did something like
git gc
then it will garbage collect all of they commits and you won't find them here!)That gives you a file like this:
You can then open this file with you favorite text editor to copy the commit/blog hashes from there. (*cough* vim macros works great for this *cough*)
Now you can log back from this commit with something like
git log --oneline <commit hash>
. Alternatively, gitk, tig, or any other git viewer should work.In your case if you find the hash for commit F the log will show you something like this,
Quick and easy! Now you can find the context behind all of those dangling commits.
P.S. Yes, I know, late post, but oh well, somebody might find it here and find it useful. (Mostly likely me in 6 months when I google this again)
We'll
git log
sometimes is not good to get all commits detail, so to view this...For Mac: Get into you git project and type:
to view you all commits in that, or:
to view you all commits in that,
then you can edit in any of your favourite browser.
I've had luck recovering the commit by looking at the reflog, which was located at
.git/logs/HEAD
I then had to scoll down to the end of the file, and I found the commit I just lost.