Git cannot upload and delete large files in Commit

1. Bug description

Because I accidentally put a packaged aab file into the commit file in a commit, so push rejected when uploading.

 Because GitHub’s file limit is 100M, but the package is too big, 170M, so it cannot be uploaded, but it is already in the Commit history, and it has been several times, so I want to delete it from the history.

2. Solution:

Delete app/release/app-release.aab in the commit record

1. To delete the commit contained in the Git history app/release/app-release.aab, you can use the Git filter-branchcommand to rewrite the history. Note that this type of operation modifies history, so make sure you understand the potential risks and back up important data before performing this operation.

2. First, make sure you are in the correct Git repository directory. Open a command line or terminal and navigate to this directory.

3. Run the following command, using filter-branchto rewrite the history:

git filter-branch --force --index-filter "git rm --cached --ignore-unmatch app/release/app-release.aab" --prune-empty --tag-name-filter cat -- --all

(Note the file name above)

4. This command traverses the entire Git history and deletes app/release/app-release.aabcommits that contain . --index-filterThe parameter uses git rm --cached --ignore-unmatchthe command to remove the file from every commit.

Git rewrites the history after the command has finished executing. Note that this may take some time, depending on the size of your project history.

 If an error is reported:

This is because you still have changes locally, you can continue to put them in the commit, if there are other errors reported, just modify them according to the prompts.

5. Once done, you can run the following command to clear Git's junk data:

git for-each-ref --format="delete %(refname)" refs/original | git update-ref --stdin

Just run this command

6. Upload code

git push --force origin

If an error is reported, follow the prompts to solve it.

 

Guess you like

Origin blog.csdn.net/LoveFHM/article/details/131563696