许荣@DESKTOP-A30VNHE MINGW64 ~/Desktop
$ cd learngit
许荣@DESKTOP-A30VNHE MINGW64 ~/Desktop/learngit (master)
$ git add test.txt
许荣@DESKTOP-A30VNHE MINGW64 ~/Desktop/learngit (master)
$ git commit -m "add test.txt"
[master ea4269d] add test.txt
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 test.txt
许荣@DESKTOP-A30VNHE MINGW64 ~/Desktop/learngit (master)
$ git add test.txt
许荣@DESKTOP-A30VNHE MINGW64 ~/Desktop/learngit (master)
$ git commit -m "add test.txt"
[master 6e7a140] add test.txt
1 file changed, 1 insertion(+)
许荣@DESKTOP-A30VNHE MINGW64 ~/Desktop/learngit (master)
$ rm test.txt
许荣@DESKTOP-A30VNHE MINGW64 ~/Desktop/learngit (master)
$ git status
On branch master
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
deleted: test.txt
no changes added to commit (use "git add" and/or "git commit -a")
许荣@DESKTOP-A30VNHE MINGW64 ~/Desktop/learngit (master)
$ git rm test.txt
rm 'test.txt'
许荣@DESKTOP-A30VNHE MINGW64 ~/Desktop/learngit (master)
$ git commit -m "remove test.txt"
[master 68d82f9] remove test.txt
1 file changed, 1 deletion(-)
delete mode 100644 test.txt
许荣@DESKTOP-A30VNHE MINGW64 ~/Desktop/learngit (master)
$ git checkout -- test.txt
error: pathspec 'test.txt' did not match any file(s) known to git
许荣@DESKTOP-A30VNHE MINGW64 ~/Desktop/learngit (master)
$ git add xu.txt
许荣@DESKTOP-A30VNHE MINGW64 ~/Desktop/learngit (master)
$ git commit "add xu.txt"
error: pathspec 'add xu.txt' did not match any file(s) known to git
许荣@DESKTOP-A30VNHE MINGW64 ~/Desktop/learngit (master)
$ git commit -m "add xu.txt"
[master 4e05e40] add xu.txt
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 xu.txt
许荣@DESKTOP-A30VNHE MINGW64 ~/Desktop/learngit (master)
$ rm xu.txt
许荣@DESKTOP-A30VNHE MINGW64 ~/Desktop/learngit (master)
$ git checkout -- test.txt
error: pathspec 'test.txt' did not match any file(s) known to git
许荣@DESKTOP-A30VNHE MINGW64 ~/Desktop/learngit (master)
$ git checkout -- xu.txt
许荣@DESKTOP-A30VNHE MINGW64 ~/Desktop/learngit (master)
$
总结:只要文件提交到了版本库,使用(git checkout -- xu.txt)
该命令就可以将误删的文件恢复到文件管理器中。
git-删除文件以及误删文件恢复命令
于 2021-07-18 22:36:49 首次发布