Book Image

Git Best Practices Guide

By : PIDOUX Eric
Book Image

Git Best Practices Guide

By: PIDOUX Eric

Overview of this book

Table of Contents (12 chapters)

Cleaning your mistakes


The first thing to know is that you can always clean your mistake with Git. Sometimes this will be hard or painful for your code, but you can do it!

Let's start this section with how to remove untracked files:

Erik@server:~$ git clean -n

The –n option will make a dry-run (it's always important to see what will happen before you regret it).

If you want to also remove directories and hidden files, use this one:

Erik@server:~$ git clean -fdx

With these options, you will delete new directories (-d) and hidden files (-x) and be able to force them (-f).

Reverting uncommitted changes

To explain this section, we will use an example. Let's suppose you edited a file on the production working directory, but didn't commit it. On your last push, you edited it, and the changes in production aren't needed anymore. So, your goal is to erase changes on this file and reset the file to the last committed version:

Erik@server:~$ git checkout the_filename

This command is really nice if you...