How to remove big files from old commits in bitbucket?

Member

by dana , in category: Third Party Scripts , 2 months ago

How to remove big files from old commits in bitbucket?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by lindsey.homenick , 2 months ago

@dana 

To remove big files from old commits in Bitbucket, you can use the following steps:

  1. Identify the commits that contain the big files you want to remove. You can use the following command in your terminal to list all the commits in your repository:
1
git log


  1. Once you have identified the commits that contain the big files, you can use the following command to create a new branch from the commit before the first commit that contains the big files:
1
git checkout -b new_branch_name commit_sha


  1. Next, use the following command to remove the big files from the new branch:
1
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch path_to_big_file' --prune-empty --tag-name-filter cat -- --all


Replace "path_to_big_file" with the path to the big file you want to remove.

  1. Once the big files are removed from the new branch, you can force push the changes to the remote repository:
1
git push origin new_branch_name --force


  1. Finally, you can merge the changes from the new branch into your main branch or any other branch as needed:
1
2
git checkout main
git merge new_branch_name


These steps will allow you to remove big files from old commits in Bitbucket. Remember to back up your repository before making any significant changes.