Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Removing Files in Git | More Advanced Interaction
Git Essentials
course content

Conteúdo do Curso

Git Essentials

Git Essentials

1. Introduction to Git
2. More Advanced Interaction
3. Undoing Changes
4. Working with Branches in Git

book
Removing Files in Git

In the version control world, managing files is a crucial aspect of maintaining a clean and organized project history. Git provides specific commands for removing and renaming files, ensuring that these changes are tracked efficiently. For now, we'll start with removing files.

Removing Files

The git rm command is used to remove files from both the working directory and the staging area.

Note

This command will stop the file from being tracked by Git and remove it from the .git directory.

It helps Git recognize that the file should be deleted in the next commit. Here its basic syntax:

Where <file> is the name of the file you want to remove.

File Removal Workflow

Suppose, we decided that our test.txt file is now obsolete, so it would be reasonable to remove this file. Let’s first list all non-hidden files and directories in our repository using the following command:

Our repository indeed contains the test.txt file. Now, let’s run the git rm command to remove this file:

Next, we can run the git status command:

As you can see, this change is ready to be committed, so let’s commit it with an appropriate commit message:

Our commit was successful, and since our files originally contained four lines, 4 deletions took place.

Let’s now once again list non-hidden files and directories:

As for now, there are no more non-hidden files in our repository, which proves that the deletion was successful.

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 2. Capítulo 3
We're sorry to hear that something went wrong. What happened?
some-alt