• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Undo git reset –hard before first commit

Resolved: Undo git reset –hard before first commit

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

Yeah I did an oopsie maybe. I hope this question gets enough attention because the title sounds like many different other questions here on Stackoverflow, but none of the answers I’ve found worked. But let me explain first:
(Tired,) I decided to add all my .config files to git and push them. (I was stupid+tired enough to not backup). I created a new repository with git init and added everything with git add -A. I then thought that making a .gitignore with some directories would be smart before adding and commiting everything, so I wanted to undo my git add -A.
That’s where the mistake happened, I used git reset --hard instead git rm --cached * to unstage the files.
Unfortunately, git did a git rm on everything, since there was no previous commit. And that’s where I am now. All config files gone. Many solutions like git update-ref -d HEAD, git reset (--hard) HEAD~1 and git reset followed by git ls-files -d -z | xargs -0 git checkout -- don’t because there is no commit and no branch created yet.
I also tried to find the deleted directories and files in the .git directory or trash, but this didn’t work either.
Does one of you have an idea how I could get my config files back? All I want to do is to undo the git reset…

Answer:

Git is about commits. That’s all it’s about. If there was a “good” commit that contains the stuff you’re looking for, then just find it in the reflog and check it out. But you cannot recover what was never committed.

If you have better answer, please add a comment about this, thank you!

git git-reset
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: How do I navigate a table without any easily accessible distinctions?

27/03/2023

Resolved: Can a pod make itself unavailable temporarily in kubernetes?

27/03/2023

Resolved: How to plot logistic probability for custom generalized additive model (GAM) plot?

27/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.