Git is a system centered around the idea of a save point, a commit. When you use the source control software you create many commits throughout the life cycle of the application. These save points serve a number of purposes such as showing what you did to create a given issue, this would be if you tying the commit to a system like Jira to track issues. They can also show you who did which pieces of an application in a team setting as each commit is stamped with the user making the commit. Probably the most important purpose is to provide a history of the application and specifically the different files within the repository at any given point in the development process.
Why is this important, you ask?
Ever accidentally delete a file off your file system and go “oh crap, I didn’t mean to do that”. In some cases you can go to the trash can of your favorite OS and get the file back but what if you accidentally hit “empty trash” when you only meant to delete a single file? what then? In this case you are pretty SOL.
With Git if you accidentally delete a file or an entire directory from the repository but it was present in another commit, you can get it back. If you do a pull and the pull action overwrites a file that you really wanted your changes and not the ones from the server, you can get the file back. Not only that but you can get the file back as part of the merge process. No matter what happens in Git as long as there is a commit in the repository with the state of the file that you want, you can get to that file or directory again.
Now some will say committing too much is a bad thing. Don’t know why they would but I would highly recommend that you commit often. Especially as you complete features and functionality, I would commit. These save points, these commits, can be life saving later.
So, if you run into a situation where you think your repository is toast, trashed, totaled,
How do you get them back? … well that depends…
depends on the situation and as I come across different situations I will post about them so you can check my blog for solutions.