overwritten git repo with old version of git repo, game over?
Have I totally lost all my commits? I know it was dumb, and for that I am sorry, but it was 开发者_如何转开发an innocent mistake, not thinking a workflow through properly.
EDIT
the overwrite was a manual drag and drop, no terminal commands entered.
I am on a mac.
I have time machine, and can retrieve my old new repo (if you know what I mean, my head is melting), but can I merge them (have have since made changes, deadline looking) or should I just reinstate the backup in it's entirety?
well, it will be cumbersome, but your commits will probably still be there …
run git fsck --full
(might take a while) – it will list all dangling blobs/trees/commits. inspect each danging commit with git log
/git show
/gitk
. when you find a head commit of a branch, recreate the branch with git branch <branchname> <sha1 of commit>
(you have to remember your old branch names)
since you recovered your old repository state using time machine and have your old repository now on your desktop, simplest thing to do for you would be adding a new remote and then fetching the remote commits:
git remote add old-repo /path/to/your/desktop/old-dir/.git
# sorry, no clue what the actual path might be on mac systems (~/Desktop/…?)
git fetch old-repo
after that you will have all branches from your old repository available as old-repo/branchname
. to merge them simply issue a git merge old-repo/branch
command. this is mere basic git fu to set up a repository as an additional remote and merge its changes (no magic going on here, move along)
Windows ? Linux ?
If its Windows you can attempt recovering your files using recovery tools or a hex editor that can directly read the disk. On Linux, I don't know.
But yeah if you have no backups... it's your fault ! =)
Sometimes, just sometimes you can be lucky. On windows 7, open the properties of the folder and click "Previous Versions".
I was lucky enough to find an old iPhone backup using that technique when it looked like i'd lost all!!
精彩评论