¿Cómo elimino un archivo grande que se ha cometido incorrectamente en git [duplicar]


Posible Duplicado:
¿Cómo purgar un archivo enorme del historial de confirmaciones en Git?

Hice una cosa estúpida. Imagina que he enviado un archivo de 100MB. Luego veo esto y borro este archivo y confirmo de nuevo. Este es el procedimiento normal para eliminar un archivo.

Pero ahora el efecto secundario es que mi historial es pesado porque ha guardado este archivo grande (creo que esta es la razón por la que es pesado). Solo estoy usando git local, por lo que no sincronizo en ninguna servidor.

¿Cómo puedo eliminar definitivamente este archivo y ahorrar espacio en disco?

Author: Community, 2011-11-10

3 answers

Puedes hacerlo usando el comando git filter-branch, así:

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

Puede encontrar más documentación aquí 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/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-11-10 17:00:44

El comando que está buscando es filter-branch. Le permite eliminar permanentemente archivos de un alistamiento. Este blog tiene un gran tutorial sobre cómo eliminar archivos problemáticos del repositorio

 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/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-11-10 17:00:11

Puedes tomar este gran script de David Underhill para eliminar el archivo del repositorio 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/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-11-10 16:58:41