To delete a version-controlled file from the local git repository

Source: Internet
Author: User

In some cases, we may want a clean directory, for example, my source code has all been submitted to the server's repository, the local source code I would like to delete, but there are some of the energy code directory of our own configuration, data and other files, these files are not version-controlled, If the entire source directory is deleted, these files will be deleted together! If you want a file of version control (tracked files) in a git source directory on your local hard disk, leave the file without version control (untracker files), you can use the following command:

git ls-files | xargs rm

After running the above instruction, manually delete the. Git directory and you will get a clean, versioned directory.

The above instruction has a disadvantage, that is, the empty directory will be left, not deleted, can be deleted by the following command:

For /F "tokens=*" %a in (' dir/b/ad/s directory path ^|sort/r ') do Rd "%a" /q 2>nul

The above instructions are Windows batch instructions, Linux do it yourself.
In fact, there is one of the simplest way to do this: just use git delete command to delete the source Coogan directory! But do not submit on the line, and in this way, the original source directory must not be used for source control, you must re-open a new directory check source. For SVN you can use this command: The SVN delete source directory is a clean version of the file is not versioned, if you have uncommitted changes, you will also be prompted to submit before you can delete ~

To delete a version-controlled file from the local git repository

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.