如何从从 git 克隆的项目中删除版本跟踪?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4754152/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 09:54:45  来源:igfitidea点击:

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

gitversiongit-track

提问by daustin777

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:

我可以执行 shell 命令,例如:

rm -rf .git

from my projects directory or is there a way to do this as a Git command?

从我的项目目录或有没有办法将其作为 Git 命令执行?

I used this project to learn Git and realize I made some mistakes early on in the project with moved, renamed and deleted files. I'd like to remove all Git tracking and start fresh with git init.

我使用这个项目来学习 Git,并意识到我在项目的早期犯了一些错误,包括移动、重命名和删除文件。我想删除所有 Git 跟踪并重新开始git init.

回答by bobDevil

All the data Git uses for information is stored in .git/, so removing it should work just fine. Of course, make sure that your working copy is in the exact state that you want it, because everything else will be lost. .gitfolder is hidden so make sure you turn on the Show hidden files, folders and disksoption.

Git 用于信息的所有数据都存储在 中.git/,因此删除它应该可以正常工作。当然,请确保您的工作副本处于您想要的确切状态,因为其他所有内容都将丢失。.git文件夹是隐藏的,因此请确保打开该Show hidden files, folders and disks选项。

From there, you can run git initto create a fresh repository.

从那里,您可以运行git init以创建新的存储库。

回答by Lily Ballard

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

rm -rf .git应该足够了。这将吹走所有与 Git 相关的信息。

回答by Matt C

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

除了以下步骤之外,您可能还想删除 .gitignore 文件。

  • 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.

  • 如果您想删除项目中的任何 Git 痕迹,请考虑删除 .gitignore 文件。

  • ** 如果您想将 Git 重新合并到项目中,请考虑保留 .gitignore 文件。

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

某些框架可能会自动生成 .gitignore 文件,因此您可能希望保留它。



Linux, Mac, or Unix based operating systems

基于 Linux、Mac 或 Unix 的操作系统

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

打开终端并导航到您的项目目录,即 - cd path_to_your_project

Run this command:

rm -rf .git*

运行此命令:

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.

这将从您的项目中删除 Git 跟踪和元数据。如果要保留元数据(例如 .gitignore 和 .gitkeep),则可以通过运行 .gitignore 仅删除跟踪rm -rf .git



Windows

视窗

Using the command prompt

使用命令提示符

The rmdiror rdcommandwill not delete/remove any hidden files or folders within the directory you specify, so you should use the delcommand to be sure that all files are removed from the .gitfolder.

rmdirrd命令将不会删除/删除您指定的目录范围内所有隐藏文件或文件夹,所以你应该使用的del命令,确保所有文件都从删除.git的文件夹。

  1. Open the command prompt

    1. Either click Startthen Runor hit the Windows keykey and rat the same time.

    2. Type cmdand hit enter

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

  1. 打开命令提示符

    1. 单击Start然后Run或同时按下视窗键r

    2. 类型cmd和命中进入

  2. 导航到项目目录,即 - cd path_to_your_project

  1. Run these commands

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

    2. rmdir .git

  1. 运行这些命令

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

    2. rmdir .git

The first command removes all files and folder withinthe .gitfolder. The second removes the .gitfolder itself.

第一个命令删除所有文件和文件夹.git文件夹。第二个删除.git文件夹本身。

No command prompt

没有命令提示符

  1. Open the file explorer and navigate to your project

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

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

    2. In the Advanced Settingssection, find Hidden files and Foldersunder the Files and Folderslist and select Show hidden files and folders

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

    Delete the .gitfolder Delete the .gitignorefile ** (see note at the top of this answer)

  1. 打开文件资源管理器并导航到您的项目

  2. 显示隐藏的文件和文件夹 - 请参阅本文以获取视觉指南

    1. 在工具栏上的视图菜单中,选择 Options

    2. 在该Advanced Settings部分中,Hidden files and FoldersFiles and Folders列表下找到并选择Show hidden files and folders

  3. 关闭选项菜单,您应该会看到所有隐藏的文件夹和文件,包括该.git文件夹。

    删除.git文件夹删除.gitignore文件**(请参阅此答案顶部的注释)

回答by John Yin

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

.git*手动移动所有.git文件并不是一个明智的选择,尤其是当这些文件像我的情况一样隐藏在子文件夹中时:当我通过 composer+git 安装 Skeleton Zend 2 时,.git在文件夹和子文件夹中创建了相当多的文件文件夹。

I tried rm -rf .giton my GitHub shell, but the shell can not recognize the parameter -rfof Remove-Item.

rm -rf .git在我的 GitHub shell 上尝试过,但是 shell 无法识别-rfRemove-Item的参数。

www.montanaflynn.me introduces the following shell commandto remove all .gitfiles one time, recursively! It's really working!

www.montanaflynn.me 介绍了以下shell命令,.git递归方式一次性删除所有文件!它真的有效!

find . | grep "\.git/" | xargs rm -rf

回答by Nitya Kumar

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

我正在使用 Linux 环境。我以递归方式删除了所有 Git 文件和文件夹:

rm -rf .git

rm -rf .gitkeep

回答by Rukshan Dangalla

In a Windows environment you can remove Git tracking from a project's directory by simply typing the below.

在 Windows 环境中,您只需键入以下内容即可从项目目录中删除 Git 跟踪。

rd .git /S/Q

回答by Kamesh Jungi

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

find . | grep .git | xargs rm -rf

回答by Emeka Augustine

The easiest way to solve this problem is to use a command line. Type this command rm -R .git/Then Enter... OR rm -rf .git/Press Enter...

解决这个问题最简单的方法是使用命令行。rm -R .git/输入这个命令然后回车...或rm -rf .git/按回车...

回答by SridharKritha

Windows Command Prompt (cmd) User:

Windows 命令提示符 (cmd) 用户:

You could delete '.git' recursively inside the source project folder using a single line command.

您可以使用单行命令在源项目文件夹中递归删除“.git”。

FOR /F "tokens=*" %G IN ('DIR /B /AD /S *.git*') DO RMDIR /S /Q "%G"