我想重置为提交,如果我的工作目录中有任何新文件,则应将其删除。
这是我从git reset --hard [<commit>]
所期望的行为,但是在将修改后的文件上的更改恢复为原来的状态时,它只是忽略了新文件。
考虑以下示例,我将在其中执行以下操作:
删除文件main.c
提交此更改
创建文件main.c
恢复为先前的提交
并且期望main.c
不再存在。
$:~/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