Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
devTea240885y@NeatNerdPrime @gronostaj the repo folder has been deleted, I just managed to recover the .git folder. Copied the objects and refa folder to a fresh clone .git folder doesn’t worked
-
so wait, your local repo is gone, and that included a branch you were working on taht has not been committed and has been deleted...
First i'd ensure the local git repo is back in pristine condition, so i'd simply clone from the remote first.
then, if you're lucky, you can try to recover your file s with "trash-restore - Restore for Command line trash utility." it's simply searching with your package manager for this utility, read the manpage and start recovering your files.
That way you will have recovered the files you were working on (the branch you accidentally deleted) and then, once you confirmed that all files have been recovered, do a git commit/push2remote and you're safe again -
C0D4681465yWere the changes in the branch committed?
You can use reflog, to create a branch using a commits sha1 and restore it that way.
Otherwise, well... I have some bad news. -
devTea240885y@gronostaj when I checkout to the branch that hasn’t been pushed it shows error non monotonic index
-
devTea240885y@NeatNerdPrime @C0D4 I have commited to that branch, it just hasn’t been pushed to remote, how do I read branch commits from refs/heads branch name?
-
C0D4681465y@devTea backup the current .git
Drop in your old .git and check your branches
# git branch
If the old branch is listed, you should be fine to
# git checkout oldBranch
Otherwise you can recreate the branch
# git checkout -b oldBranch
and
# git reflog
If it has tracked your commits, run
# git reset --hard HEAD@{1}
1 being the index of the commit you want to roll back too on the current branch.
It that doesn't work, this is a one of those learning moments of why to push regularly 😉 -
@devTea Ok to avoid any confusion, which end is "pristine"? the local repo or the remote?
Reading your last comment i ass-u-me it's the local repo that is pristine and the remote is broken.
If that is the case it's not terrible to delete an end of a repo, since every clone of a git repo contains the full history of the project. It's the main property of git, every clone has the full history project.
Knowing this, it's just a matter of cleaning the location of the remote, no need to "recover" files since your local copy of the repo contains everything.
On your remote just re-init your repo (git init) and do a "git push <remote> --all" and you should be good! -
devTea240885y@NeatNerdPrime the local got deleted with a branch that hasn’t been pushed to remote, I managed to restore the .git folder using file recovery software but seems like it restore all of the past repo commit. I just need a way to track my commits on the branch in that .git folder
-
devTea240885y@C0D4 bad config file in line 1, when I used the remote config file and copy all of the .git/objects and .git/refs folder to the new cloned repo it shows error non monotonic index
-
C0D4681465y@devTea sounds like .git is corrupt. is it on MacOS by any chance, not judging its probably has ._ files in there somewhere
Either way, i'd try following this, best to backup that project as things may go screwy.
https://stackoverflow.com/a/...
and yes, i have this bookmarked for those bad days where things or dev servers shit themselves. -
@devTea Ah, in that case, please see what i said half hour ago, and try to:
* clone from remote in pristine condition, ensure your local repo is clean, you can use "git fsck" for that (it will check integrity of your repo)
* Create a NEW branch, name it "recovery" or something, be poëtic creative
* use the "trash-restore" CLI utility (assuming you run linux on your machine) to try to recover as many files as possible. If you use another OS, use any file restore utility fit for that OS
* While doing this do NOT overwrite any part of your .git folder , since that is now "pristine". Just concern yourself about the lost source code files.
* if you have recovered your source code files, do check your files, and if all is well, commit the files into the branch
* Push everything to remote.
* Do a sigh of relief, everything si back okay now. -
Do you still have the relevant files in your text editor's buffer by any chance?
-
@devTea idk, by luck you could still have the files open in it. Sublime has saved me that way.
-
devTea240885y@C0D4 @NeatNerdPrime will try both of your method
Tldr for future reader: how to recover old repo git objects to fresh cloned repo -
@devTea Please take my advise "as-is" without any warranty!
If shit hits the fan, recover from backups if possible... you do make backups, right?
Related Rants
Accidentally rm -rf a git repo, one of the branch still not pushed to remote yet. I managed to use file recovery software to recover the .git folder, any idea what to do next?
question
git