How do I remove version tracking from a project cloned from git?

后端 未结 10 1217
太阳男子
太阳男子 2020-11-28 00:00

I want to remove all version tracking from a project\'s directory.

What is the correct method to do this?

Can I do a shell command such as:

r         


        
相关标签:
10条回答
  • 2020-11-28 00:27

    In addition to the steps below, you may want to also remove the .gitignore file.

    • Consider removing the .gitignore file if you want to remove any trace of Git in your project.

    • ** Consider leaving the .gitignore file if you would ever want reincorporate Git into the project.

    Some frameworks may automatically produce the .gitignore file so you may want to leave it.


    Linux, Mac, or Unix based operating systems

    Open a terminal and navigate to the directory of your project, i.e. - cd path_to_your_project.

    Run this command:

    rm -rf .git*
    

    This will remove the Git tracking and metadata from your project. If you want to keep the metadata (such as .gitignore and .gitkeep), you can delete only the tracking by running rm -rf .git.


    Windows

    Using the command prompt

    The rmdir or rd command will not delete/remove any hidden files or folders within the directory you specify, so you should use the del command to be sure that all files are removed from the .git folder.

    1. Open the command prompt

      1. Either click Start then Run or hit the Windows key key and r at the same time.

      2. Type cmd and hit enter

    2. Navigate to the project directory, i.e. - cd path_to_your_project

    1. Run these commands

      1. del /F /S /Q /A .git

      2. rmdir .git

    The first command removes all files and folder within the .git folder. The second removes the .git folder itself.

    No command prompt

    1. Open the file explorer and navigate to your project

    2. Show hidden files and folders - refer to this article for a visual guide

      1. In the view menu on the toolbar, select Options

      2. In the Advanced Settings section, find Hidden files and Folders under the Files and Folders list and select Show hidden files and folders

    3. Close the options menu and you should see all hidden folders and files including the .git folder.

      Delete the .git folder Delete the .gitignore file ** (see note at the top of this answer)

    0 讨论(0)
  • 2020-11-28 00:31

    It's not a clever choice to move all .git* by hand, particularly when these .git files are hidden in sub-folders just like my condition: when I installed Skeleton Zend 2 by composer+git, there are quite a number of .git files created in folders and sub-folders.

    I tried rm -rf .git on my GitHub shell, but the shell can not recognize the parameter -rf of Remove-Item.

    www.montanaflynn.me introduces the following shell command to remove all .git files one time, recursively! It's really working!

    find . | grep "\.git/" | xargs rm -rf
    
    0 讨论(0)
  • 2020-11-28 00:33

    I am working with a Linux environment. I removed all Git files and folders in a recursive way:

    rm -rf .git
    
    rm -rf .gitkeep
    
    0 讨论(0)
  • 2020-11-28 00:38

    From root folder run

    find . | grep .git
    

    Review the matches and confirm it only contains those files you want to delete and adjust to suit. Once satisfied, run

    find . | grep .git | xargs rm -rf

    0 讨论(0)
  • 2020-11-28 00:41

    rm -rf .git should suffice. That will blow away all Git-related information.

    0 讨论(0)
  • 2020-11-28 00:42

    The easiest way to solve this problem is to use a command line. Type this command

    rm -R .git/
    

    OR

    rm -rf .git/
    
    0 讨论(0)
提交回复
热议问题