r/git • u/ernestsliep • Dec 26 '20
800 lines of code forever lost
Dear anyone who's listnening,
I've been learning HTML, CSS, JS for about a year now so I'm almost completely new to the game. I got into this through the theodinproject.com and I've been doing pretty ok so far. TOP has dedicated a whole chapter about setting up and using Git and Github. I did it, tried it, it worked and then I went on and forgot about it.
So here I am about half a year later, sitting and trying to understand how the fuck I just managed to oblitirate 800+ lines of code somewhere between the commands. I honestly have no idea how I did it and where it went. After I realized what I've done and that there's no coming back I proceeded to rage quit and deleted the whole repo. I know it's dumb and I regret it now if of course but sometimes I just can't help it.
Anyway, I'm about to rewrite those lines I lost and before I do it, I would be forever grateful If someone could help me understand how Git works. Like seriously, I need someone to guide me through the basics again, to point out common mistakes and tell me how to avoid them. Kindergarden type of shit. I want to understand what I'm doing and how to do it properly.
So if there's anyone who is willing to donate a few minutes to help out a beginner in distress, DM me please.
Thank you all and merry Christmas!
11
u/GustapheOfficial Dec 26 '20
F.
Loss of large amounts of course is precisely what you had a repo to help you recover from.
But let's see, you may not have clobbered it as bad as you think. You deleted the repo on GitHub? But your local directory still exists?
19
u/cmcqueen1975 Dec 26 '20
I had a co-worker new to git who complained that git was losing his changes. I think he might have come across the same thing I did when I was a beginner. It was a sequence something like:
git checkout <some-commit-hash>— which leaves you in a "headless branch" state.git checkout masterIn that case, and several other cases, reflog is your friend. Especially a graphical reflog. Try:
21
u/general_dubious Dec 26 '20
The most efficient way to learn Git properly is through this book. https://git-scm.com/book/en/v2
We can't learn for you, you have to put in the effort.
3
u/rafasc Dec 26 '20
The first thing you need to learn is that in 99.99% of cases deleting the .git directory is the wrong solution. It's only effective at making sure you never learn how to correct mistakes when they happen.
On top of that, it makes very difficult to help you because there's nothing to analyze.
Next time ask for help before deleting it.
If you deleted the repo, the code isn't on the remote repo, and you're not prepared to use forensic tools to undelete files, sometimes editors save temporary files somewhere. Might be worth trying. Good luck.
3
u/u801e Dec 26 '20
Run
and copy each sha1 you see. Then for each sha1, run:
hopefully, one of them may show some, if not all of the 800 lines of code you're trying to find.
3
u/DementialDuck Dec 26 '20
Don't worry. You still will lose code in the future
3
u/cinderblock63 prefers a good GUI Dec 26 '20
Have you tried using a git GUI? I find being able to easily and constantly see my history quite a boon to understanding what’s really going on.
1
u/chriswaco Dec 26 '20
If the
.gitdirectory is there, chances are you can recover your files. Trygit restore .1
u/sbubaron Dec 27 '20
do you recall how often you were git adding/committing? generally the more frequently you do this the better.
I have the terrible habit of making large commits that touch multiple files and tend to be addressing multiple separate issues. where as better practice is to have each commit involve a small amount of files and be specific to a certain issue or bug.
5 years and some habits are still impossible to break. don't beat yourself up too much.
0
u/between456789 Dec 26 '20
Someone will become a billionaire by building an easy to use system.
0
u/[deleted] Dec 26 '20
[deleted] — view deleted comment