In Git, delete operation is a modification, we combat it, to add a new file test.txt
to Git and submit:
$ git add test.txt $ git commit -m "add test.txt" [master b84166e] add test.txt 1 file changed, 1 insertion(+) create mode 100644 test.txt
In general, you usually directly in the file manager to delete useless files, or use the rm
command delete:
$ rm test.txt
This time, Git know you delete a file, therefore, workspace and repository on the inconsistency, the git status
command will tell you which files are deleted immediately:
$ git status On branch master 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: test.txt no changes added to commit (use "git add" and/or "git commit -a")
Now you have two options, one sure you want to delete the file repository, then use the command git rm
to delete, and git commit
:
$ git rm test.txt rm 'test.txt' $ git commit -m "remove test.txt" [master d46f35e] remove test.txt 1 file changed, 1 deletion(-) delete mode 100644 test.txt
Now, the file is deleted from the repository.
Another case is deleting the wrong, because what else the repository, so you can easily recover accidentally deleted the files to the latest version:
$ git checkout -- test.txt
git checkout
In fact, the workspace is a replacement version with the version in the repository, regardless of the workspace is modified or deleted, can be "a key to restore."
summary
Command git rm
is used to delete a file. If a file has been submitted to the repository, so you never have to worry about mistakenly deleted, but be careful, you can only restore files to the latest version, you will lose the contents of the most recent commit your changes .