git apply
git
Uso
git apply [--check|-3] <patch>Aplica un archivo diff a tu árbol de trabajo; no crea commit ni lee el autor del parche, por eso los parches recibidos por correo se aplican con am.
Opciones habituales
| Opción | Significado |
|---|---|
| --check | report whether it would apply, change nothing |
| -3 | fall back to a three-way merge and leave conflict markers |
| --index | apply to the working tree and stage it |
| --cached | apply to the index only |
| -R | apply in reverse, undoing the patch |
| -p<n> | strip n leading path components |
| --stat | show what the patch touches |
Ejemplos
git apply --check fix.patchtells you if it fits before you try
git apply -3 fix.patchapplies it and leaves conflicts to resolve by hand
git apply -R fix.patchtakes an applied patch back out
Lo confuso es que deshacer tiene varias formas: mover a dónde apunta una rama no es lo mismo que añadir un commit que la revierte.
Cómo leerlo
- Los corchetes [ ] marcan una parte que puedes omitir.
- Los puntos suspensivos … indican que puedes poner varios.
- Las opciones distinguen mayúsculas: en algunos comandos -r y -R no hacen lo mismo.
Preguntas
Q. ¿Qué hace git apply?
Aplica un archivo diff a tu árbol de trabajo; no crea commit ni lee el autor del parche, por eso los parches recibidos por correo se aplican con am.
Q. ¿Cómo se escribe?
git apply [--check|-3] <patch> — los corchetes marcan lo que puedes omitir.
Q. ¿Cuántas opciones vale la pena saber?
Aquí van 7; la lista completa está en man git. Este comando está en git.
Comandos relacionados
página man: man git-apply