Skip to content

Instantly share code, notes, and snippets.

@cansik
Last active May 19, 2022 06:48
Show Gist options
  • Select an option

  • Save cansik/ad9bdc68d9513016e963f71f722d8a50 to your computer and use it in GitHub Desktop.

Select an option

Save cansik/ad9bdc68d9513016e963f71f722d8a50 to your computer and use it in GitHub Desktop.

Revisions

  1. cansik revised this gist Jun 14, 2020. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions rm-lfs.sh
    Original file line number Diff line number Diff line change
    @@ -16,7 +16,6 @@ FILESTXT="$REPODIR-lfs.txt"
    if [ -d "$REPODIR" ]; then rm -Rf "$REPODIR"; fi

    # clone
    # export GIT_LFS_SKIP_SMUDGE=1 # without lfs
    git lfs uninstall
    git clone "$REPO" "$REPODIR"

    @@ -56,9 +55,13 @@ git reflog expire --expire=now --all && git gc --prune=now --aggressive

    # remove files from head and commit
    for LFSFILE in "${LSFFILES[@]}"; do
    # maybe used --cached to not delete file locally
    FILENAME=`echo "$LFSFILE" | rev | cut -d '/' -f 1 | rev`

    # completely removes file
    git rm -f "*$FILENAME"

    # removes file from lfs an adds them to normal git
    # git rm --cached "*$FILENAME"
    # git add "*$FILENAME"
    done
    git commit -m "removed lfs files from repository"
  2. cansik revised this gist Jun 14, 2020. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions rm-lfs.sh
    Original file line number Diff line number Diff line change
    @@ -59,6 +59,7 @@ for LFSFILE in "${LSFFILES[@]}"; do
    # maybe used --cached to not delete file locally
    FILENAME=`echo "$LFSFILE" | rev | cut -d '/' -f 1 | rev`
    git rm -f "*$FILENAME"
    # git add "*$FILENAME"
    done
    git commit -m "removed lfs files from repository"

  3. cansik revised this gist Jun 14, 2020. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions rm-lfs.sh
    Original file line number Diff line number Diff line change
    @@ -20,8 +20,6 @@ if [ -d "$REPODIR" ]; then rm -Rf "$REPODIR"; fi
    git lfs uninstall
    git clone "$REPO" "$REPODIR"

    read -p "Press enter to continue"

    # list all files
    cd "$REPODIR"
    git lfs ls-files --all > "../$FILESTXT"
    @@ -75,4 +73,6 @@ read -p "Press enter to push changes!"
    git push --force

    # remove chunk
    rm -rf .git/lfs
    rm -rf .git/lfs
    git lfs install
    exit
  4. cansik revised this gist Jun 14, 2020. 1 changed file with 16 additions and 11 deletions.
    27 changes: 16 additions & 11 deletions rm-lfs.sh
    Original file line number Diff line number Diff line change
    @@ -41,16 +41,6 @@ done < "../$FILESTXT"
    # remove git lfs
    git rm .gitattributes

    # remove files from head and commit
    for LFSFILE in "${LSFFILES[@]}"; do
    # maybe used --cached to not delete file locally
    FILENAME=`echo "$LFSFILE" | rev | cut -d '/' -f 1 | rev`
    git rm -f "*$FILENAME"
    done
    git commit -m "removed lfs files from repository"

    read -p "Press enter to continue"

    # run bfg cleaner for each file
    LSFFILENAMES=()
    for LFSFILE in "${LSFFILES[@]}"; do
    @@ -66,8 +56,23 @@ bfg --delete-files "$LFSARGS"
    # reflog
    git reflog expire --expire=now --all && git gc --prune=now --aggressive

    # remove files from head and commit
    for LFSFILE in "${LSFFILES[@]}"; do
    # maybe used --cached to not delete file locally
    FILENAME=`echo "$LFSFILE" | rev | cut -d '/' -f 1 | rev`
    git rm -f "*$FILENAME"
    done
    git commit -m "removed lfs files from repository"

    echo ""
    echo ""
    echo "FINISHED! now run 'git push --force' to upload it to the server!"
    echo "After that install git lfs again: 'git lfs install'"
    echo "And remove git lfs-index from repo: 'rm -rf .git/lfs'"
    echo "And remove git lfs-index from repo: 'rm -rf .git/lfs'"

    read -p "Press enter to push changes!"

    git push --force

    # remove chunk
    rm -rf .git/lfs
  5. cansik revised this gist Jun 14, 2020. 1 changed file with 19 additions and 7 deletions.
    26 changes: 19 additions & 7 deletions rm-lfs.sh
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,12 @@
    #/bin/zsf
    #/bin/zsh

    echo "converting lfs to normal git repo..."

    if [ $# -eq 0 ]
    then
    echo "Use: rm-lfs.sh [http-git-url]"
    exit
    fi

    REPO=$1
    REPODIR=`echo "$REPO" | rev | cut -d '/' -f 1 | rev`
    @@ -12,8 +17,11 @@ if [ -d "$REPODIR" ]; then rm -Rf "$REPODIR"; fi

    # clone
    # export GIT_LFS_SKIP_SMUDGE=1 # without lfs
    git lfs uninstall
    git clone "$REPO" "$REPODIR"

    read -p "Press enter to continue"

    # list all files
    cd "$REPODIR"
    git lfs ls-files --all > "../$FILESTXT"
    @@ -24,26 +32,28 @@ while IFS= read -r line
    do
    # caution, sometimes it's an asterix, sometimes a dash!
    # https://stackoverflow.com/a/36585611/1138326
    LFSFILE=`echo "$line" | awk -F" - " '{print $2}'`
    NORMLINE=`echo $line | sed 's/*/-/'`
    echo "$NORMLINE"
    LFSFILE=`echo "${NORMLINE#* - }"`
    LSFFILES+=( "$LFSFILE" )
    done < "../$FILESTXT"

    # remove git lfs
    git lfs uninstall
    git rm .gitattributes

    # remove files from head and commit
    for LFSFILE in ${LSFFILES[@]}; do
    for LFSFILE in "${LSFFILES[@]}"; do
    # maybe used --cached to not delete file locally
    FILENAME=`echo "$LFSFILE" | rev | cut -d '/' -f 1 | rev`
    git rm -f "*$FILENAME"
    # git add "$LFSFILE" # use only when cached
    done
    git commit -m "removed lfs files from repository"

    read -p "Press enter to continue"

    # run bfg cleaner for each file
    LSFFILENAMES=()
    for LFSFILE in ${LSFFILES[@]}; do
    for LFSFILE in "${LSFFILES[@]}"; do
    FILENAME=`echo "$LFSFILE" | rev | cut -d '/' -f 1 | rev`
    LSFFILENAMES+=( "$FILENAME" )
    done
    @@ -58,4 +68,6 @@ git reflog expire --expire=now --all && git gc --prune=now --aggressive

    echo ""
    echo ""
    echo "FINISHED! now run 'git push --force' to upload it to the server!"
    echo "FINISHED! now run 'git push --force' to upload it to the server!"
    echo "After that install git lfs again: 'git lfs install'"
    echo "And remove git lfs-index from repo: 'rm -rf .git/lfs'"
  6. cansik revised this gist Jun 14, 2020. 1 changed file with 6 additions and 7 deletions.
    13 changes: 6 additions & 7 deletions rm-lfs.sh
    Original file line number Diff line number Diff line change
    @@ -10,18 +10,20 @@ FILESTXT="$REPODIR-lfs.txt"
    # prepare
    if [ -d "$REPODIR" ]; then rm -Rf "$REPODIR"; fi

    # clone without lfs
    export GIT_LFS_SKIP_SMUDGE=1
    # clone
    # export GIT_LFS_SKIP_SMUDGE=1 # without lfs
    git clone "$REPO" "$REPODIR"

    # list all files
    cd "$REPODIR"
    git lfs ls-files --all > "../$FILESTXT".
    git lfs ls-files --all > "../$FILESTXT"

    # create lfs file index
    LSFFILES=()
    while IFS= read -r line
    do
    # caution, sometimes it's an asterix, sometimes a dash!
    # https://stackoverflow.com/a/36585611/1138326
    LFSFILE=`echo "$line" | awk -F" - " '{print $2}'`
    LSFFILES+=( "$LFSFILE" )
    done < "../$FILESTXT"
    @@ -56,7 +58,4 @@ git reflog expire --expire=now --all && git gc --prune=now --aggressive

    echo ""
    echo ""
    echo "FINISHED! now run 'git push' to upload it to the server!"

    git lfs push origin master --all
    git push --no-verify --force
    echo "FINISHED! now run 'git push --force' to upload it to the server!"
  7. cansik revised this gist Jun 13, 2020. No changes.
  8. cansik revised this gist Jun 13, 2020. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions rm-lfs.sh
    Original file line number Diff line number Diff line change
    @@ -35,7 +35,7 @@ for LFSFILE in ${LSFFILES[@]}; do
    # maybe used --cached to not delete file locally
    FILENAME=`echo "$LFSFILE" | rev | cut -d '/' -f 1 | rev`
    git rm -f "*$FILENAME"
    git add "$LFSFILE"
    # git add "$LFSFILE" # use only when cached
    done
    git commit -m "removed lfs files from repository"

    @@ -51,7 +51,7 @@ LFSARGS="{"$(IFS=,; printf '%s' "${LSFFILENAMES[*]}")"}"
    echo $LFSARGS
    bfg --delete-files "$LFSARGS"

    # refolg
    # reflog
    git reflog expire --expire=now --all && git gc --prune=now --aggressive

    echo ""
  9. cansik created this gist Jun 13, 2020.
    62 changes: 62 additions & 0 deletions rm-lfs.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,62 @@
    #/bin/zsf

    echo "converting lfs to normal git repo..."


    REPO=$1
    REPODIR=`echo "$REPO" | rev | cut -d '/' -f 1 | rev`
    FILESTXT="$REPODIR-lfs.txt"

    # prepare
    if [ -d "$REPODIR" ]; then rm -Rf "$REPODIR"; fi

    # clone without lfs
    export GIT_LFS_SKIP_SMUDGE=1
    git clone "$REPO" "$REPODIR"

    # list all files
    cd "$REPODIR"
    git lfs ls-files --all > "../$FILESTXT".

    # create lfs file index
    LSFFILES=()
    while IFS= read -r line
    do
    LFSFILE=`echo "$line" | awk -F" - " '{print $2}'`
    LSFFILES+=( "$LFSFILE" )
    done < "../$FILESTXT"

    # remove git lfs
    git lfs uninstall
    git rm .gitattributes

    # remove files from head and commit
    for LFSFILE in ${LSFFILES[@]}; do
    # maybe used --cached to not delete file locally
    FILENAME=`echo "$LFSFILE" | rev | cut -d '/' -f 1 | rev`
    git rm -f "*$FILENAME"
    git add "$LFSFILE"
    done
    git commit -m "removed lfs files from repository"

    # run bfg cleaner for each file
    LSFFILENAMES=()
    for LFSFILE in ${LSFFILES[@]}; do
    FILENAME=`echo "$LFSFILE" | rev | cut -d '/' -f 1 | rev`
    LSFFILENAMES+=( "$FILENAME" )
    done

    echo "removing all files with a single command"
    LFSARGS="{"$(IFS=,; printf '%s' "${LSFFILENAMES[*]}")"}"
    echo $LFSARGS
    bfg --delete-files "$LFSARGS"

    # refolg
    git reflog expire --expire=now --all && git gc --prune=now --aggressive

    echo ""
    echo ""
    echo "FINISHED! now run 'git push' to upload it to the server!"

    git lfs push origin master --all
    git push --no-verify --force