Discuss / Git / 说说我的看法,欢迎撕逼

说说我的看法,欢迎撕逼

Topic source

当用rm test命令删除文件时,这和在文件中加几行一样,git都会把他们认做是一种修改,这是你用git status会显示 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) 这次操作并没有提交到stage中,这里可以看到git add 和git rm其实是一个类型的操作,这时工作区已经没有了test文件,但版本库里有啊,此时有俩个选择, 1:决意彻底删除,先git rm test将修改提交到stage中,再git commit,好了彻底删除了。 2:脑子抽了,恢复文件,git checkout -- test,用ls看一下,果然有了。

如果你是用git rm test 来删除,这样ls一下工作目录中是没有test了,另外也已经提交到stage了,看一下status, Changes to be committed: (use "git reset HEAD <file>..." to unstage)

    deleted:    test2

待commit中了,想恢复 git reset HEAD test,再git status一下 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:    test2

现在就和上面一样了。

我觉得多看看status就懂了


  • 1

Reply