How can I recover main.c and learn Git with Keil?
Asked by
9ms jitter
Git and Keil are central to my microcontrollers class, but I'm still struggling to understand how they work together. While trying to return my project to the state of my first lab assignment and undo some edits, I accidentally deleted my main.c file. I'm not sure how to recover it or where to start learning the workflow, especially since my professor and TAs avoid giving specific answers that might reveal the lab solutions.
Answers
Your file may still be recoverable. Run `git reflog` to see previous positions of HEAD, including before the reset or checkout. Once you find the commit containing the file, restore just main.c with `git checkout -- main.c` or the newer equivalent, `git restore --source= -- main.c`. Avoid running `git clean -fd` until youโre sure you donโt need any untracked files, since that can permanently remove them.
Reply to this answer
For learning, start with the basic Git ideas separately from the Keil-specific workflow: commits are saved snapshots, checkout or restore changes the files in your working directory, and reflog records where your branch and HEAD have been. Practice in a throwaway folder by making small commits, editing a file, and restoring it. That lets you learn the commands without risking your lab project.
Reply to this answer
Add your answer
Answers are reviewed before publication.
9ms jitter: Thanks, I wasnโt sure where to look after the file disappeared. Iโll check the reflog before trying anything else.