I've been working with Git and making commits to track my progress. Unfortunately, whenever I encounter issues, I tend to use the command `git reset --hard`, which ends up deleting my commits. I've noticed that I can see my entire history when I run `git reflog`. Is there a way to recover my lost commits to demonstrate my consistent work on GitLab?
5 Answers
Have you checked out sites like [learngitbranching.js.org](https://learngitbranching.js.org/)? It's an interactive way to understand Git better. I found it super helpful for learning!
Getting into a structured Git workflow could really help! If you're the only one on the project, keep it simple: create a feature branch for each task you work on. Once done, you can merge it back into the main branch, keeping your main branch safe from mishaps.
It seems like you might want to rethink using `git reset --hard`. It's usually not the best option unless things are really broken. You can cherry-pick the commits to bring them back into your history. That way, you can keep your main branch clean and still reference your previous work.
Also, consider checking [ohshitgit.com](https://ohshitgit.com/). It’s a great resource for quick Git help and recovery tips!
Next time you want to start fresh, consider creating a branch before resetting. For instance, you could use `git checkout -b bad_branch` to save your work and then reset your main branch safely. Even now, you can still recover your work by checking out a commit from `git reflog` and creating a branch from there. Alternatively, try cherry-picking those commits you wish to recover.
Related Questions
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically
[Centos] Delete All Files And Folders That Contain a String