cómo revertir archivos eliminados no comprometidos (eliminados con rm simple) a la última confirmación de git

By mistake I rm -rf a directory in my git repository. The changes are not commited and I wanted to revert this change and go back to my last git commit.

# On branch release-1
# Changes not staged for commit:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       deleted:    dir/file1
#       [....]

As the files were deleted I was nit able to do git checkout -- <file> Así que lo hice git checkout -- instead, but this did not work.

Therefore I took a shortcut: stashed the changes

$  git stash
Saved working directory and index state WIP on release-1: d2dbff3 removed the CVS $Id lines
Checking out files: 100% (394/394), done.
HEAD is now at d2dbff3 removed the CVS $Id lines

And now is all OK.

I have the impression that stashing is a bit of brute force approach. Is it possible to do a checkout of the current branch (the whole one without giving any file) discarding any change?

preguntado el 01 de febrero de 12 a las 22:02

1 Respuestas

A corto plazo, puede utilizar git stash drop to get the superfluous entry out of your stash. In the future, you can use git checkout HEAD -- dir to get the head commit version of dir.

Respondido 02 Feb 12, 02:02

+1 I was so obfuscated with the lost files that I did not think of giving a dir instead of a file to the checkout command :-(, thanks - Pablo Marín-García

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.