Jak usunąć duży plik błędnie popełniony w git [duplicate]

Możliwy duplikat:
Jak wyczyścić ogromny plik z historii commitów w Git?

Zrobiłam coś głupiego. Wyobraź sobie, że popełniłem plik 100MB. Wtedy widzę to i usuwam ten plik i zatwierdzam ponownie. Jest to normalna procedura usuwania pliku.

Ale teraz efektem ubocznym jest to, że moja historia jest ciężka, ponieważ zapisano ten duży plik(wierzę, że to dlatego jest ciężka). Używam tylko lokalnego Gita, więc nie Synchronizuję się w żadnym serwer.

Jak mogę definitywnie usunąć ten plik i zaoszczędzić miejsce na dysku?

Author: Community, 2011-11-10

3 answers

Możesz to zrobić używając komendy git filter-branch, w następujący sposób:

git filter-branch --tree-filter 'rm -rf path/to/your/file' HEAD

Więcej dokumentacji można znaleźć tutaj http://dalibornasevic.com/posts/2-permanently-remove-files-and-folders-from-a-git-repository

 117
Author: Leo,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-11-10 17:00:44

Komenda, której szukasz to filter-branch. Pozwala na trwałe usunięcie plików z rekrutacji. Ten blog zawiera świetny samouczek na temat usuwania problematycznych plików z repozytorium

 25
Author: JaredPar,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-11-10 17:00:11

Możesz użyć tego wspaniałego skryptu od Davida Underhilla aby usunąć plik z repozytorium 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's 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
files=$@
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
 14
Author: topek,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-11-10 16:58:41