Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to delete multiple lfs files

We are working on an unreal project and thinking about using bitbucket/source tree. But I fear lfs wont give us enough control. I tested uploading multiple lfs files, but it seems I can only delete them 1 by 1. So if I upload 200 texture files and need to delete 100 of them, I can only delete them 1 by 1?

1 answer

0 votes
Syahrul Atlassian Team Jan 11, 2022

Hi @Evan Robinson 

G'Day!

We don't have a feature to bulk delete the LFS files at this moment, but it's possible to delete them via the API. We do have an existing feature request on this, please Vote & Watch so that you'll get an update whenever we have any at:

While we don't have a UI feature to bulk delete the LFS files, it's possible to delete the LFS files via API, and by using the API you can create a script to bulk delete the LFS files.

I do have a script you can use, but do note that we don't officially support this script, so please use it at your own risk and tweak it as you wish.

  1. You need to get the list of the LFS OID files first, so run the following commands in the repositories
    git lfs ls-files -l | awk -F " " '{print $1}' > lfs.txt
    

    This will print and store the LFS OID in text files of lfs.txt

    • Use these commands to list out the files and OID so you can filter out which files to keep or and remove the OID from lfs.txt list
      git lfs ls-files -l 
  2. Once done, copy the following script and save it as .sh. Then ensure that it has all the necessary permission to execute and simply run the commands to bulk delete your LFS files
    #!/bin/bash
    
    file="lfs.txt"
    
    credential="username:app_password"
    
    i=0
    
    while read line || [ -n "$line" ]
    do 
        i=$((i+1))
        echo "File number : $i"
        echo "LFS Object ID (OID) : $line" 
        cmd=$(curl -s -w "\nHTTP Code:  %{http_code}\n" --user $credential -X DELETE "https://api.bitbucket.org/internal/repositories/<Workspacename>/<Repositoriesname>/lfs/$line")
        echo "Response : $cmd"
        echo ""
    done < $file
    
    echo ""
    echo "Total LFS Object ID in $file :" 
    grep -c "" $file
    

I hope this helps

Cheers,
Syahrul

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bitbucket

⭐ Calling all Bitbucket and DevOps experts: Special showcase opportunity ⭐

Hi, Bitbucket community! Are you a DevOps practitioner (or know one in your network)? Do you have DevOps tips, tricks, or learnings you'd like to share with the community? If so, we'd love to hea...

1,513 views 4 8
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you