Home > Article > Development Tools > How to delete all files in Git repository with git
When using Git for version control, sometimes we need to delete all files in the Git repository. This is useful in two situations:
So, how to delete all files in Git? The following are three common methods:
This operation will clear all files and history records in the Git repository. If you want to start a new Git repository from scratch, you can use this method.
Open the directory where the Git warehouse is located and delete all files:
rm -rf ./*
Then execute the following command to return the Git warehouse to its initial state :
git init
This command will reinitialize the Git repository and clear all history and tracked files.
This operation will keep the .git directory in the Git repository, but delete all other files.
Open the directory where the Git warehouse is located and delete all files:
rm -rf ./*
Then execute the following command to refresh the Git status:
git add . git commit -m "Remove all files"
This command will add all file deletions to Git and create a new commit. This way you keep the history in your Git repository and delete all other files.
If you don’t want to use the command line to delete all files, you can also use the Git command line tool to delete all files.
Execute the following command to list the files tracked in the current Git repository:
git ls-files
Then execute the following command to delete all files:
git rm -r --cached .
This command will delete all files in the current Git repository and add the deletion operation to Git. However, it does not delete files in the local file system.
No matter which method you use, deleting all files in a Git repository is an easy task. Just choose a method and execute it. This operation is very useful when you need to start over or re-plan version control.
The above is the detailed content of How to delete all files in Git repository with git. For more information, please follow other related articles on the PHP Chinese website!