Aquí hay un alias rebase-last-five
para comenzar. Recreará la rama actual, por lo que solo se incluirán en la historia las cinco confirmaciones más recientes. Probablemente sea mejor hacer de esto una secuencia de comandos (git-rebase-last-five.sh
) que esté disponible en un directorio en su PATH
; Git buscará y usará scripts llamados git-....sh
sin necesidad de ninguna configuración especial. La secuencia de comandos debería hacer más comprobación de errores y manejo que este alias simple.
$ git config --global alias.rebase-last-five '!b="$(git branch --no-color | cut -c3-)" ; h="$(git rev-parse $b)" ; echo "Current branch: $b $h" ; c="$(git rev-parse $b~4)" ; echo "Recreating $b branch with initial commit $c ..." ; git checkout --orphan new-start $c ; git commit -C $c ; git rebase --onto new-start $c $b ; git branch -d new-start ; git gc'
caveat.emptor: No prestar atención a la warnings about changing history. Para obtener más información, consulte las páginas man
(git help <command>
o online).
Un ejemplo de uso:
$ git --version
git version 1.7.12.rc2.16.g034161a
$ git log --all --graph --decorate --oneline
* e4b2337 (HEAD, master) 9
* e508980 8
* 01927dd 7
* 75c0fdb 6
* 20edb42 5
* 1260648 4
* b3d6cc8 3
* 187a0ef 2
* e5d09cf 1
* 07bf1e2 initial
$ git rebase-last-five
Current branch: master e4b2337ef33d446bbb48cbc86b44afc964ba0712
Recreating master branch with initial commit 20edb42a06ae987463016e7f2c08e9df10fd94a0 ...
Switched to a new branch 'new-start'
[new-start (root-commit) 06ed4d5] 5
1 file changed, 1 insertion(+)
create mode 100644 A
First, rewinding head to replay your work on top of it...
Applying: 6
Applying: 7
Applying: 8
Applying: 9
Deleted branch new-start (was 06ed4d5).
Counting objects: 35, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (15/15), done.
Writing objects: 100% (35/35), done.
Total 35 (delta 4), reused 0 (delta 0)
$ git log --all --graph --decorate --oneline
* a7fb54b (HEAD, master) 9
* 413e5b0 8
* 638a1ae 7
* 9949c28 6
* 06ed4d5 5
Esto podría ayudar: http://stackoverflow.com/questions/250238/collapsing-a-git-repositorys-history –
¿Seguro que deseas _remove_ todos los viejos commits? Significa también eliminar sus cambios. GIT no almacena el "estado actual" en cada confirmación, solo almacena un cambio. Lo que quieres hacer es aplastar todos los compromisos anteriores en uno, ¿no? – amorfis