Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 51 additions & 51 deletions book/07-git-tools/sections/rewriting-history.asc
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
[[_rewriting_history]]
=== Rewriting History
Reescribiendo la Historia

Many times, when working with Git, you may want to revise your commit history for some reason.
One of the great things about Git is that it allows you to make decisions at the last possible moment.
You can decide what files go into which commits right before you commit with the staging area, you can decide that you didn’t mean to be working on something yet with the stash command, and you can rewrite commits that already happened so they look like they happened in a different way.
This can involve changing the order of the commits, changing messages or modifying files in a commit, squashing together or splitting apart commits, or removing commits entirely – all before you share your work with others.
Muchas veces, al trabajar con Git, vas a querer confirmar tu historia por alguna razón.
Una de las grandes cualidades de Git es que te permite tomar decisiones en el último momento.
Puede decidir qué archivos entran en juego antes de comprometerse con el área de ensayo, puedes decidir que no querías estar trabajando en algo todavía con el comando de alijos, y puedes reescribir confirmaciones que ya hayan pasado haciendo parecer que fueron hechos de diferente manera.
Esto puede desenvolverse en el cambio de las confirmaciones, cambiando mensajes o modificando los archivos en un cometido, aplastando o dividiendo confirmaciones enteramente – todo antes de que compartas tu trabajo con otras personas.

In this section, you’ll cover how to accomplish these very useful tasks so that you can make your commit history look the way you want before you share it with others.
En esta sección, verás cómo complementar esas tareas tan útiles que harán parece que la confirmación de tu historia parezca del modo en el cual quisiste compartirla.

[[_git_amend]]
==== Changing the Last Commit
==== Cambiando la última confirmación

Changing your last commit is probably the most common rewriting of history that you’ll do.
You’ll often want to do two basic things to your last commit: change the commit message, or change the snapshot you just recorded by adding, changing and removing files.
Cambiar la última confirmación es probablemente lo más común que le harás a tu historia.
Comúnmente querrás hacer dos cosas en tu ultima confirmación: cambiar la confirmación del mensaje, o cambiar la parte instantánea que acabas de agregar sumando, cambiando y removiendo archivos.

If you only want to modify your last commit message, it’s very simple:
Si solamente quieres cambiar la confirmación del mensaje final, es muy sencillo:

[source,console]
----
$ git commit --amend
----

That drops you into your text editor, which has your last commit message in it, ready for you to modify the message.
When you save and close the editor, the editor writes a new commit containing that message and makes it your new last commit.
Esto te envía al editor de texto, el cual tiene tu confirmación final, listo para modificarse en el mensaje.
Cuando guardes y cierres el editor, el editor escribe una nueva confirmación conteniendo el mensaje y lo con tu ultima confirmación.

If you’ve committed and then you want to change the snapshot you committed by adding or changing files, possibly because you forgot to add a newly created file when you originally committed, the process works basically the same way.
You stage the changes you want by editing a file and running `git add` on it or `git rm` to a tracked file, and the subsequent `git commit --amend` takes your current staging area and makes it the snapshot for the new commit.
Si ya ha cambiado su última confirmación y luego quiere cambiar la instantánea que confirmo al agregar o cambiar archivos, esto es por que posiblemente olvidó agregar un archivo recién creado cuando se confirmó originalmente, el proceso trabaja prácticamente de la misma manera.
Tu manejas los cambios que quieras editando el archivo y oprimiendo `git add` en este o `git rm` a un archivo adjunto, y el subsecuente git commit --amend toma tu área de trabajo actual y la vuelve una instantánea para la nueva confirmación.

You need to be careful with this technique because amending changes the SHA-1 of the commit.
It’s like a very small rebase – don’t amend your last commit if you’ve already pushed it.
Debes ser cuidadoso con esta técnica porque puedes modificar los cambios del SHA-1 de la confirmación
Es como un muy pequeño rebase – no necesitas modificar tu ultima confirmación si ya el haz puesto.

[[_changing_multiple]]
==== Changing Multiple Commit Messages
==== Cambiando la confirmación de múltiples mensajes

To modify a commit that is farther back in your history, you must move to more complex tools.
Git doesn’t have a modify-history tool, but you can use the rebase tool to rebase a series of commits onto the HEAD they were originally based on instead of moving them to another one.
With the interactive rebase tool, you can then stop after each commit you want to modify and change the message, add files, or do whatever you wish.
You can run rebase interactively by adding the `-i` option to `git rebase`.
You must indicate how far back you want to rewrite commits by telling the command which commit to rebase onto.
Para modificar una confirmación que está más atrás en tu historia, deberás aplicar herramientas más complejas
Git no tiene una herramienta para modificar la historia, pero puedes usar la herramienta de rebase para rebasar ciertas series confirmaciones en el HEAD en el que se basaron originalmente en lugar de moverlos a otro.
Con la herramienta interactiva del rebase, puedes parar justo después de cada confirmación que quieras modificar y cambiar su mensaje, añadir archivos, o hacer cualquier cosa que quieras
Puedes ejecutar el rebase interactivamente agregando el `-i` option to `git rebase`.
De igual manera debes indicar que tan atrás quieres regresar para reescribir las confirmaciones escribiendo en el comando cual confirmación quieres rebasar.

For example, if you want to change the last three commit messages, or any of the commit messages in that group, you supply as an argument to `git rebase -i` the parent of the last commit you want to edit, which is `HEAD~2^` or `HEAD~3`.
It may be easier to remember the `~3` because you’re trying to edit the last three commits; but keep in mind that you’re actually designating four commits ago, the parent of the last commit you want to edit:
Por ejemplo, si quieres cambiar las confirmaciones de los tres últimos mensajes, o cualquiera de los mensajes de confirmación de ese grupo, proporcionas un argumento para lo `git rebase -i` que quieras modificar de tu ultima confirmación, el cual es `HEAD~2^` or `HEAD~3` .
Debería ser más fácil el recordar el ~3 porque estás tratando de editar las últimas tres confirmaciones; pero ten en mente que estás designando actualmente cuatro confirmaciones atrás, la parte del ultimo cometido que deseas editar:

[source,console]
----
$ git rebase -i HEAD~3
----

Remember again that this is a rebasing command – every commit included in the range `HEAD~3..HEAD` will be rewritten, whether you change the message or not.
Don’t include any commit you’ve already pushed to a central server – doing so will confuse other developers by providing an alternate version of the same change.
Recuerda de Nuevo es este es un comando de rebase – cualquier confirmación incluida en el rango de `HEAD~3..HEAD` será reescrita, aun si cambias el mensaje o no.
No incluyas cualquier confirmación que ya hayas enviado al servidor central – si lo haces esto confundirá a los demás desarrolladores proporcionando una versión alternativa del mismo cambio.

Running this command gives you a list of commits in your text editor that looks something like this:
Utilizar este comando te da una lista de las confirmaciones en tu editor de texto que se ve como este:

[source,console]
----
Expand All @@ -77,8 +77,8 @@ pick a5f4a0d added cat-file
# Note that empty commits are commented out
----

It’s important to note that these commits are listed in the opposite order than you normally see them using the `log` command.
If you run a `log`, you see something like this:
Es importante el notar que estas confirmaciones son escuchadas en el orden contrario de la que tú normalmente las verías usando el comando de `log`.
Si utilizaras un comando de `log`, verías algo como esto.

[source,console]
----
Expand All @@ -88,14 +88,14 @@ a5f4a0d added cat-file
f7f3f6d changed my name a bit
----

Notice the reverse order.
The interactive rebase gives you a script that it’s going to run.
It will start at the commit you specify on the command line (`HEAD~3`) and replay the changes introduced in each of these commits from top to bottom.
It lists the oldest at the top, rather than the newest, because that’s the first one it will replay.
Nótese que el orden esta al revés.
El rebase interactivo te da un script que va a utilizarse.
Este empezará en la confirmación que especificas en la línea de comandos (`HEAD~3`) y reproducir los cambios introducidos en cada una de estas confirmaciones de arriba a abajo.
Este acomoda los más viejos en la parte de arriba, y va bajando hasta los más nuevos, porque ese será el primero en reproducirse

You need to edit the script so that it stops at the commit you want to edit.
To do so, change the word `pick' to the word `edit' for each of the commits you want the script to stop after.
For example, to modify only the third commit message, you change the file to look like this:
Necesitaras editar el script para que se detenga en la confirmación que quieres editar.
Para hacer eso, cambia la palabra `pick' por la frase `edit' para cada una de las confirmaciones en las que quieres que el script se detenga.
Por ejemplo, para modificar solamente la tercera confirmación del mensaje, cambiarias el archivo para que se viera algo así:

[source,console]
----
Expand All @@ -104,7 +104,7 @@ pick 310154e updated README formatting and added blame
pick a5f4a0d added cat-file
----

When you save and exit the editor, Git rewinds you back to the last commit in that list and drops you on the command line with the following message:
Cuando guardes y salgas del editor, Git te enviará atrás a la última confirmación en la lisa y te llevará a la línea de comando con el siguiente mensaje:

[source,console]
----
Expand All @@ -119,30 +119,30 @@ Once you’re satisfied with your changes, run
git rebase --continue
----

These instructions tell you exactly what to do.
Estas instrucciones te dirán exactamente qué hacer.
Type

[source,console]
----
$ git commit --amend
----

Change the commit message, and exit the editor.
Cambia la confirmación del mensaje, y sal del editor.
Then, run

[source,console]
----
$ git rebase --continue
----

This command will apply the other two commits automatically, and then you’re done.
If you change pick to edit on more lines, you can repeat these steps for each commit you change to edit.
Each time, Git will stop, let you amend the commit, and continue when you’re finished.
Este comando te permitirá aplicar las otras dos confirmaciones automáticamente, y después de esto estás listo.
Si decides cambiar y elegir editar en más líneas, puedes repetir estos pasos para cada confirmación que cambies en cada edición.
Cada vez, Git se parará, permitiéndote modificar la confirmación y continuar cuando hayas terminado

==== Reordering Commits
==== Reordenando Confirmaciones

You can also use interactive rebases to reorder or remove commits entirely.
If you want to remove the ``added cat-file'' commit and change the order in which the other two commits are introduced, you can change the rebase script from this
De igual manera puedes usar rebases interactivos para reordenar o remover confirmaciones enteramente.
Si quieres remover la ``added cat-file'' confirmación y cambiar el orden en el cual las otras dos confirmaciones son introducidas, puedes cambiar el rebase en el script de esto:

[source,console]
----
Expand All @@ -151,7 +151,7 @@ pick 310154e updated README formatting and added blame
pick a5f4a0d added cat-file
----

to this:
A esto:


[source,console]
Expand All @@ -160,14 +160,14 @@ pick 310154e updated README formatting and added blame
pick f7f3f6d changed my name a bit
----

When you save and exit the editor, Git rewinds your branch to the parent of these commits, applies `310154e` and then `f7f3f6d`, and then stops.
You effectively change the order of those commits and remove the ``added cat-file'' commit completely.
Cuando guardes y salgas del editor, Git te recordará de tu rama de padres de estas confirmaciones, aplicando 310154e y después f7f3f6d, y después se parará.
Cambias efectivamente el orden de esas confirmaciones y eliminas la “added cat-file’’ confirmación completamente.

[[_squashing]]
==== Squashing Commits
==== Unir confirmaciones

It’s also possible to take a series of commits and squash them down into a single commit with the interactive rebasing tool.
The script puts helpful instructions in the rebase message:
También es posible el tomar series de confirmaciones y unirlas todas en una sola confirmación con la herramienta interactiva de rebase.
El script pone instrucciones que en el mensaje de rebase:

[source,console]
----
Expand Down