Home > Article > Development Tools > How to delete files on git
Deleting files on Git is a very basic and common operation in Git warehouse management. However, for developers who are just starting to use Git, this operation may not be so obvious. In this article, we will explain how to delete files on Git.
First, we need to understand the two ways to delete files in Git: deleting files in the working directory and deleting files in the Git repository. These two methods will affect the status of the file in Git and the use of the file in your development process.
Deleting files in the working directory
Deleting files in the working directory is the simplest way to delete files. You only need to enter in the command line:
$ rm <name_of_file>
where <name_of_file>
is the name of the file you want to delete. This command will delete the specified file directly from your working directory. However, the file still exists in your Git repository.
Delete files in Git repository
If you want to completely delete files in Git repository, you need to use the following two Git commands: git rm
and git commit
.
First, use the following command to remove the file you want to delete from the Git repository:
$ git rm <name_of_file>
This command will delete the file from the Git repository and add it to the deletion list.
Next, you need to commit this modification to the Git repository. Use the following Git command:
$ git commit -m "Removed <name_of_file>"
This command will save the changes to the local Git repository. Note that this operation does not push the changes to the Git server. You need to use the git push
command to push changes to the remote Git repository.
Summary
This article introduces two ways to delete files in Git. The easiest way is to delete the file in the working directory, but the file will remain in the Git repository. If you want to completely delete files in the Git repository, you need to use the git rm
and git commit
commands. Remember to back up your files before performing Git operations to avoid data loss.
The above is the detailed content of How to delete files on git. For more information, please follow other related articles on the PHP Chinese website!