In Git, the deletion is also a modification operation, we do the actual combat, first add a new file test.txt
to Git and commit:
In general, you usually delete the useless files directly in the File Manager, or rm
delete them by command:
At this point, git knows that you deleted the file, so the workspace and repository are inconsistent, and the git status
command will immediately tell you which files were deleted:
Now that you have two options, one is to remove the file from the repository, delete it with a command git rm
, and git commit
:
The file is now deleted from the repository.
If you want to recover, you can only recover by the version number rollback, all delete to be cautious, submit to be cool.
Tip: Manually delete files first, then use git rm <file> git add<file> effect is the same.
The other is wrong, because the repository is still there, so it is easy to restore the deleted files to the latest version:
git checkout
Instead, replace the workspace version with the version in the repository, which can be "one-click Restore", regardless of whether the workspace is modified or deleted.
Summary
Command git rm
to delete a file. If a file has been submitted to the repository, then you will never have to worry about accidental deletion, but be careful that you can only recover files to the latest version, and you will lose the content that was modified after the last commit
Git (delete files)