How can I recover main.c and learn Git with Keil?

September 15, 2026 2 answers
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

freckles and mud
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.

9ms jitter: Thanks, I wasnโ€™t sure where to look after the file disappeared. Iโ€™ll check the reflog before trying anything else.

Reply to this answer
bishop_2diag
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.

Related Discussions