Created
January 6, 2025 16:18
-
-
Save upadrian/254ad012d41f06bb247ca1cbb8ee5f82 to your computer and use it in GitHub Desktop.
Eliminar todo el commit history de un repositorio
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Si por error, quedan incluídos en el repositorio archivos con datos sensibles, o archivos que no deberían estar incluídos, puede ser necesario eliminar commits anteriores. | |
| # Esta solución borra todo el historial de commits, y deja el estado actual del repositorio como último commit. | |
| # La idea básicamente es generar un branch nuevo (huérfano), a partir del "main" branch, después borrar el "main", renombrar el branch recién creado como "main" y forzar el update de git. | |
| # En gitlab, "main" puede estar protejido, por lo que para hacer esto, hay que quitar esta protección: | |
| # https://stackoverflow.com/questions/32246503/fix-gitlab-error-you-are-not-allowed-to-push-code-to-protected-branches-on-thi | |
| # Fuente: | |
| # https://clearinsights.io/blog/how-to-remove-all-git-commit-history/ | |
| # Copiar el ranch actual (main) a un nuévo branch huérfano | |
| git checkout --orphan latest_branch | |
| # Agregar todos los archivos al nuevo branch | |
| git add -A | |
| # crear un nuevo commit con los archivos agregados | |
| git commit -am "your new commit message" | |
| # Borrar el branch "main" | |
| git branch -D main | |
| # Renombrar el branch actual (latest_branch) a "main" | |
| git branch -m main | |
| # Forzar el checkout | |
| git push -f origin main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment