Chapter 3. Filesystem interactions

 

This chapter covers

  • Renaming, moving, and removing versioned files or directories
  • Telling Git to ignore certain files or changes
  • Deleting all untracked or ignored files or directories
  • Resetting all files to their previously committed state
  • Temporarily stashing and reapplying changes to files

When working with a project in Git, you’ll sometimes want to move, delete, change, and/or ignore certain files in your working directory. You could mentally keep track of the state of important files and changes, but this isn’t a sustainable approach. Instead, Git provides commands for performing filesystem operations for you.

Understanding the Git filesystem commands will allow you to quickly perform these operations rather than being slowed down by Git’s interactions. Let’s start with the most basic file operations: renaming or moving a file.

Technique 17 Renaming or moving a file: git mv

Technique 18 Removing a file: git rm

Technique 19 Resetting files to the last commit: git reset

Technique 20 Deleting untracked files: git clean

Technique 21 Ignoring files: .gitignore

Technique 22 Deleting ignored files

Technique 23 Temporarily stashing some changes: git stash

Technique 24 Reapplying stashed changes: git stash pop

Technique 25 Clearing stashed changes: git stash clear

Technique 26 Assuming files are unchanged

Technique 27 Listing assumed-unchanged files

Technique 28 Stopping assuming files are unchanged

3.1. Summary