Git (delete files)

Source: Internet
Author: User

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 checkoutInstead, 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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.