![]() |
Sometimes, you may accidentally commit a large file to your Git repository, making it unwieldy and slow. Large files can significantly increase the size of your repository, making operations like cloning, fetching, and pulling slower and more cumbersome. This can be particularly problematic in team environments where multiple developers are constantly interacting with the repository. Fortunately, Git provides powerful tools to rewrite commit history and remove such files. In this guide, we’ll show you how to remove a specific file, bigfile.html, from your Git commit history using the filter-branch command. Steps to Remove Large FilesStep 1: Remove the FileFirst, you need to remove large_file.html from the commit history. Open your terminal and navigate to your repository’s directory. Run the following command: git filter-branch --force --index-filter \
'git rm --cached --ignore-unmatch large_file.html' \
--prune-empty --tag-name-filter cat -- --all
![]() file structure initially ![]() This command goes through your commit history and removes bigfile.html from all commits. ![]() after removing large_file.html Step 2: Clean UpAfter removing the file, you need to clean up your repository to finalize the changes. Run these commands: git reflog expire --expire=now --all
git gc --prune=now --aggressive
![]() These commands help reduce the repository size by expiring all reflogs and pruning all unreachable objects. Step 3: Force Push the ChangesFinally, you need to push the cleaned-up history to your remote repository. Be cautious with this step, as force pushing will overwrite the remote history and can cause issues for other collaborators. Make sure to inform your team before proceeding. Run: git push --force
![]() how to Remove a Large File from Commit History in Git Important Notes
|
Reffered: https://www.geeksforgeeks.org
Git |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |