Подтвердить что ты не робот

Как удалить большой файл, ошибочно зафиксированный в git

Возможный дубликат:
Как очистить огромный файл от фиксации истории в Git?

Я сделал глупую вещь. Представьте, что я сделал файл размером 100 Мбайт. Затем я вижу это и удаляю этот файл и фиксирую его снова. Это обычная процедура для удаления файла.

Но теперь побочным эффектом является то, что моя история тяжелая, потому что она сохранила этот большой файл (я считаю, что именно поэтому он тяжелый). Я использую только локальный git, поэтому я не синхронизируюсь на любом сервере.

Как я могу окончательно удалить этот файл и сохранить дисковое пространство?

4b9b3361

Ответ 3

Вы можете взять этот отличный script из David Underhill, чтобы удалить файл из репозитория git:

#!/bin/bash
set -o errexit

# Author: David Underhill
# Script to permanently delete files/folders from your git repository.  To use 
# it, cd to your repository root and then run the script with a list of paths
# you want to delete, e.g., git-delete-history path1 path2

if [ $# -eq 0 ]; then
    exit 0
fi

# make sure we're at the root of git repo
if [ ! -d .git ]; then
    echo "Error: must run this script from the root of a git repository"
    exit 1
fi

# remove all paths passed as arguments from the history of the repo
[email protected]
git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch $files" HEAD

# remove the temporary history git-filter-branch otherwise leaves behind for a long time
rm -rf .git/refs/original/ && git reflog expire --all &&  git gc --aggressive --prune