删除分支上的文件README.md

zhangxing 2020-05-06

MINGW64 /f/Git (master)
$ rmdir README.md
rmdir: failed to remove ‘README.md‘: Not a directory-------------------------------------->删目录的命令-20200307HH MINGW64 /f/Git (master)
$ rm -rf README.md-20200307HH MINGW64 /f/Git (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:    README.md

no changes added to commit (use "git add" and/or "git commit -a")

-20200307HH MINGW64 /f/Git (master)
$ git add README.md

-20200307HH MINGW64 /f/Git (master)
$ git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        deleted:    README.md


-20200307HH MINGW64 /f/Git (master)
$ git commit -"clear"
fatal: could not lookup commit lear-------------------------------------------------------->所以这样做的是错的。删除一个应该用git rm

-20200307HH MINGW64 /f/Git (master)
$ git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        deleted:    README.md


-20200307HH MINGW64 /f/Git (master)
$ git restore --staged  README.md---------------------------------------------------------------> 把删除撤销了

-20200307HH MINGW64 /f/Git (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:    README.md

no changes added to commit (use "git add" and/or "git commit -a")

现在正真才是在干删除的事情:

MINGW64 /f/Git (master)
$ git rm README.md
rm ‘README.md‘

-20200307HH MINGW64 /f/Git (master)
$ git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        deleted:    README.md


-20200307HH MINGW64 /f/Git (master)
$ git commit -m"trash"
[master 4b0a1dc] trash
 1 file changed, 1 deletion(-)
 delete mode 100644 README.md

-20200307HH MINGW64 /f/Git (master)
$ git status
On branch master
nothing to commit, working tree clean

相关推荐