i'm bit puzzled git situation.
i'm working on git versioned project , noticed commits thought on master branch weeks ago missing. remembered these commits pushed else on feature branch “feature/something", not exist anymore.
i tried find missing commits fix our mistake , push them on permanent branch. in team, each developer puts id of ticket working on in commit message. know sure ticket id (e.g 1234) in commit message i’m looking for, tried:
git log --all --grep=1234 git log -g --grep=1234 git log --all | grep 1234 git reflog | grep 1234 all of these commands returned nothing.
at point, give , remembered our git repo integrated slack, searched 1234 in slack history , found commits hashes. tried:
git show hash1 git show hash2 which surprisingly worked! displayed commit information. commits there, somehow still on local repository. wanted double check how missed them:
git reflog | grep hash1 git branch --contains hash1 git fsck --lost-found | grep hash1 nothing.
git fsck --unreachable | grep hash1 unreachable commit hash1 and here is, in unreachable commits list.
but big project , git fsck --unreachable returns tons of commits, how have found lost commit keyword ? if did not have third party tool logging git activity, maybe have tried piping output of git fsck git show somehow , grepping on result seems lot find commit know right here somewhere.
p.s: i’m sorry can’t share repo, it’s private project following should reproduce situation:
user a:
git clone <repo> git checkout -b feature/something # add commit git commit -m “special-keyword" git push origin feature/something user b:
git clone <repo> git push origin :feature/something now user b works weeks, , tries find commit "special-keyword" pushed user a.
when delete branch, delete reflog. there's separate reflog head retain reference commits on deleted branch, only if you've had them checked-out.
the difference between --lost-found , --unreachable subtle:1 see git glossary, and/or illustration below. in general, using --lost-found and/or --unreachable find such commit(s) (and --lost-found, write ids .git/lost-found/commit directory, think has side effect of protecting them garbage collection).
in particular case, commit looking not tip-most commit of deleted branch. is, suppose before deleting feature/something have this, 2 recent commits made on feature branch:
a <- b <- c <-- master \ d <- e <-- feature/something now delete feature/something, losing ids of commits e , d both. both ids show in output of git fsck --unreachable, e's id show (and saved) git fsck --lost-found, because commit d "reachable" e if/when restore commit.
finding commit
how have found lost commit keyword?
it's bit tricky. best bet using git show on unreachable commits, like:
git show $(git fsck --unreachable | git cat-file --batch-check | awk '/commit/ { print $3 }') now can search keyword(s) in log messages (or diffs). internal $(...) sequence method extracting candidate ids: want commits, not tags, trees, , blobs. once have ids, regular git commands (git log -1, git show, etc) can used those.
1in fact, learned myself writing answer.
Comments
Post a Comment