I careless copied .git
from one project (A) to another (B), with a remote scp -r (A) (B)
.
I would like to recover a usable state of the git repo. I can remove (A)'s .git objects. From there, how can I best go about finding tips of git branches and rebuilding a useful state of the repo.
Unfortunately, I don't have another copy of (B), and my mistake wiped out the metadata.
Your only problem is restoring the refs. All
B
's objects are still there, but any ofA
's names (branches, remotes, tags, ...) that matchedB
names overwrote the object pointers.Start with
which will show you dangling commits and all the roots, most projects have just one, you can then do
git log --graph --decorate --oneline --ancestry-path $the $dangling $commits --not $the $roots
. Since the copy also overwrote your reflogs, if you stomped on all the refs this will find all your missing history.