How to do it...

In order to not accidentally delete any changes you have in your working tree when you are about to undo a commit, you can have a look at the current state of your working directory with git status command (as we already saw). If you have changes and you want to keep them, you can stash them away before undoing the commit and retrieve them afterward. Git provides a stash command that can put unfinished changes away, so it is easy to make quick context switches without losing work. The stash functionality is described further in Chapter 11, Tips and Tricks. For now, you can think of the stash command as a stack where you can put your changes and pop them later.

With the hello_world.c file in the working directory modified to ...

Get Git Version Control Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.