Use git rebase --interactive
para editar ese compromiso anterior, ejecutar git reset HEAD~
y luego git add -p
agregar algunos, luego hacer un compromiso, luego agregar un poco más y hacer otro compromiso, tantas veces como desee. Cuando haya terminado, ejecute git rebase --continue
, y tendrá todas las confirmaciones divididas anteriormente en su pila.
Importante : tenga en cuenta que puede jugar y hacer todos los cambios que desee, y no tener que preocuparse por perder los cambios antiguos, porque siempre puede ejecutar git reflog
para encontrar el punto en su proyecto que contiene los cambios que desea, (llamémoslo a8c4ab
) y luego git reset a8c4ab
.
Aquí hay una serie de comandos para mostrar cómo funciona:
mkdir git-test; cd git-test; git init
ahora agrega un archivo A
vi A
agregue esta línea:
one
git commit -am one
luego agregue esta línea a A:
two
git commit -am two
luego agregue esta línea a A:
three
git commit -am three
ahora el archivo A se ve así:
one
two
three
y nuestro git log
aspecto es el siguiente (bueno, yo usogit log --pretty=oneline --pretty="%h %cn %cr ---- %s"
bfb8e46 Rose Perrone 4 seconds ago ---- three
2b613bc Rose Perrone 14 seconds ago ---- two
9aac58f Rose Perrone 24 seconds ago ---- one
Digamos que queremos dividir la segunda cometió, two
.
git rebase --interactive HEAD~2
Esto trae un mensaje que se ve así:
pick 2b613bc two
pick bfb8e46 three
Cambie el primero pick
a an e
para editar esa confirmación.
git reset HEAD~
git diff
nos muestra que acabamos de descifrar el commit que hicimos para el segundo commit:
diff --git a/A b/A
index 5626abf..814f4a4 100644
--- a/A
+++ b/A
@@ -1 +1,2 @@
one
+two
Pongamos en escena ese cambio y agreguemos "y un tercero" a esa línea en el archivo A
.
git add .
Este suele ser el punto durante un rebase interactivo en el que correríamos git rebase --continue
, porque generalmente solo queremos volver a nuestra pila de confirmaciones para editar una confirmación anterior. Pero esta vez, queremos crear una nueva confirmación. Entonces correremos git commit -am 'two and a third'
. Ahora editamos el archivo A
y agregamos la línea two and two thirds
.
git add .
git commit -am 'two and two thirds'
git rebase --continue
Tenemos un conflicto con nuestro compromiso three
, así que resolvámoslo:
Vamos a cambiar
one
<<<<<<< HEAD
two and a third
two and two thirds
=======
two
three
>>>>>>> bfb8e46... three
a
one
two and a third
two and two thirds
three
git add .; git rebase --continue
Ahora nuestro git log -p
aspecto es el siguiente:
commit e59ca35bae8360439823d66d459238779e5b4892
Author: Rose Perrone <roseperrone@fake.com>
Date: Sun Jul 7 13:57:00 2013 -0700
three
diff --git a/A b/A
index 5aef867..dd8fb63 100644
--- a/A
+++ b/A
@@ -1,3 +1,4 @@
one
two and a third
two and two thirds
+three
commit 4a283ba9bf83ef664541b467acdd0bb4d770ab8e
Author: Rose Perrone <roseperrone@fake.com>
Date: Sun Jul 7 14:07:07 2013 -0700
two and two thirds
diff --git a/A b/A
index 575010a..5aef867 100644
--- a/A
+++ b/A
@@ -1,2 +1,3 @@
one
two and a third
+two and two thirds
commit 704d323ca1bc7c45ed8b1714d924adcdc83dfa44
Author: Rose Perrone <roseperrone@fake.com>
Date: Sun Jul 7 14:06:40 2013 -0700
two and a third
diff --git a/A b/A
index 5626abf..575010a 100644
--- a/A
+++ b/A
@@ -1 +1,2 @@
one
+two and a third
commit 9aac58f3893488ec643fecab3c85f5a2f481586f
Author: Rose Perrone <roseperrone@fake.com>
Date: Sun Jul 7 13:56:40 2013 -0700
one
diff --git a/A b/A
new file mode 100644
index 0000000..5626abf
--- /dev/null
+++ b/A
@@ -0,0 +1 @@
+one