Eliminar archivo de confirmación
Tengo una lista de archivos modificados en el repositorio git. Hay un archivo que no quiero confirmar en este momento. Puedo hacer:
git commit -a
Para confirmar todos los archivos y luego eliminar de alguna manera ese archivo de la confirmación actual? Después de tal eliminación todavía debe estar en la lista de archivos no comprometidos.
7 answers
Quieres hacer esto:
git add -u
git reset HEAD path/to/file
git commit
Asegúrese y haga esto desde el nivel superior del repositorio; add -u
agrega cambios en el directorio actual (recursivamente).
La línea clave le dice a git que restablezca la versión de la ruta dada en el índice (el área de preparación para el commit) a la versión de HEAD (el commit actualmente comprobado).
Y advertencia anticipada de un gotcha para otros que lean esto: add -u
etapas todas las modificaciones, pero no agrega archivos sin seguimiento. Esto es lo mismo que commit -a
lo hace. Si también desea agregar archivos sin seguimiento, use add .
para agregar recursivamente todo.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-08-25 12:50:55
git rm --cached
lo eliminará del conjunto de confirmaciones ("anularlo"); eso suena como lo que quieres.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-11-26 05:27:07
Si ya has empujado tu commit entonces. do
git checkout origin/<remote-branch> <filename>
git commit --amend
Y si no ha empujado los cambios en el servidor puede utilizar
git reset --soft HEAD~1
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-11-19 08:13:08
Use stash; así:
git add .
git reset Files/I/Want/To/Keep
git stash --keep-index
git commit -a -m "Done!"
git stash pop
Si accidentalmente confirma un archivo y desea reescribir su historial de git, use:
git reset HEAD~1 path/to/file
git commit -a -m "rollback"
git rebase -i HEAD~2
Y squash a los dos commits principales. Puede escribir un script de ayuda para hacer cualquiera de estos si tiene un conjunto conocido de archivos que prefiere no confirmar automáticamente.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-06-12 08:27:50
Tal vez también podría usar stash para almacenar temporalmente sus modificaciones en un archivo de parche y luego volver a aplicarlo (después de un checkout para volver a la versión anterior). Esto podría estar relacionado con este otro tema : ¿Cómo extraería un solo archivo (o cambios en un archivo) de un alijo de git?.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 12:10:32
Respuesta:
git reset HEAD path/to/file
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-02-07 15:16:29
Tienes que restablecer ese archivo al estado original y confirmarlo de nuevo usando --amend
. Esto se hace más fácil usando git checkout HEAD^
.
Preparar demo:
$ git init
$ date >file-a
$ date >file-b
$ git add .
$ git commit -m "Initial commit"
$ date >file-a
$ date >file-b
$ git commit -a -m "the change which should only be file-a"
Indique antes:
$ git show --stat
commit 4aa38f84e04d40a1cb40a5207ccd1a3cb3a4a317 (HEAD -> master)
Date: Wed Feb 7 17:24:45 2018 +0100
the change which should only be file-a
file-a | 2 +-
file-b | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
Aquí viene: restaurar la versión anterior
$ git checkout HEAD^ file-b
Commit it:
$ git commit --amend file-b
[master 9ef8b8b] the change which should only be file-a
Date: Wed Feb 7 17:24:45 2018 +0100
1 file changed, 1 insertion(+), 1 deletion(-)
Indicar después de:
$ git show --stat
commit 9ef8b8bab224c4d117f515fc9537255941b75885 (HEAD -> master)
Date: Wed Feb 7 17:24:45 2018 +0100
the change which should only be file-a
file-a | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-02-07 16:31:20