Git is a very popular version control tool, which is widely used in software development to track code changes. During the software development process, developers may find that there are some unnecessary or outdated files in the repository. These files may be large files, causing the repository to take up too much space, resulting in reduced git usage efficiency. In this case, we need to learn how to delete large files.
First, we need to clone the git repository locally so that we can operate the repository. Use the git clone command to clone the remote repository to the local directory.
git clone <remote-repo-url>
BFG is a command line tool that can help us delete large files and sensitive data. It can help us quickly reduce the size of the repository. size. Before installing BFG Cleaner on your system, you must first install the Java runtime environment.
apt-get install openjdk-8-jdk
After the installation is complete, we can download the latest version of BFG Cleaner through the BFG download page.
wget http://repo1.maven.org/maven2/com/madgag/bfg/1.13.0/bfg-1.13.0.jar
Use BFG Cleaner to quickly delete large files by running the following command.
java -jar bfg.jar --delete-files <path-to-file>
In the above command, <path-to-file>
is the path of the large file to be deleted. The BFG cleaner will replace the file with a file that should be "harmless" to the Git repository before marking it for deletion.
Once we have successfully marked the large files for deletion and replaced them, we need to update the Git repository to reflect the deletion of the files. In order to accomplish this, we need to run the following command:
git reflog expire --expire=now --all && git gc --prune=now --aggressive
Finally, we need to push the updated Git repository back to the remote repository to ensure that the other Developers can access these changes.
git push -f origin master
In the above command, master
is the default Git branch name.
Summary
In software development, cleaning up large files in the Git repository can enable us to reduce the size of the repository and improve the efficiency of Git usage. With BFG Cleaner, we can quickly and safely delete large files, enjoy Git tagging and other features.
The above is the detailed content of How to delete large files in git. For more information, please follow other related articles on the PHP Chinese website!