Contenido del Curso
Git Essentials
Git Essentials
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.
¡Gracias por tus comentarios!