I'd like to reset to a commit and, if there's any new file in my working directory, it should be deleted.
That was the behavior I've expected from git reset --hard [<commit>]
but it simply ignores new files while reverting changes on modified files to how it was.
Consider the following example, where I do the following:
delete file
main.c
commit this change
create file
main.c
revert to previous commit
And expected main.c
to no longer exist.
$:~/dev/gittests$ ls
main.c
$:~/dev/gittests$ rm main.c
$:~/dev/gittests$ git add *
fatal: pathspec '*' não encontrou nenhum arquivo
$:~/dev/gittests$ git status
No ramo master
Mudanças a serem submetidas:
(use "git reset HEAD <file>..." to unstage)
deleted: main.c
$:~/dev/gittests$ git commit -m "deleted main"
[master 84de2d3] deleted main
1 file changed, 0 insertions(+), 0 deletions(-)
delete mode 100644 main.c
$:~/dev/gittests$ ls
$:~/dev/gittests$ touch main.c
$:~/dev/gittests$ ls
main.c
$:~/dev/gittests$ git status
No ramo master
Arquivos não monitorados:
(utilize "git add <arquivo>..." para incluir o que será submetido)
main.c
nada adicionado ao envio mas arquivos não registrados estão presentes (use "git add" to registrar)
$:~/dev/gittests$ git log
commit 84de2d30505cb6526a2f28918c8b37e4c086db59 (HEAD -> master)
Author: ******
Date: Wed May 15 01:34:27 2019 -0300
deleted main
commit 04382fc20f2fe6dc36ce4443c97f83b786f87781
Author: *****
Date: Wed May 15 01:14:02 2019 -0300
initial commit
$:~/dev/gittests$ git reset --hard 84de2d
HEAD is now at 84de2d3 deleted main
$:~/dev/gittests$ ls
main.c