How to fully delete a git repository created with

2020-01-22 13:49发布

I created a git repository with git init. I'd like to delete it entirely and init a new one.

标签: git git-init
23条回答
贪生不怕死
2楼-- · 2020-01-22 14:03

u can also deleted these folders and files where u have a git repository

http://storage9.static.itmages.com/i/16/0410/h_1460324963_2968655_d38544bf73.png

查看更多
做自己的国王
3楼-- · 2020-01-22 14:05

Git keeps all of its files in the .git directory. Just remove that one and init again.

If you can't find it, it's because it is hidden.

  • In Windows 7, you need to go to your folder, click on Organize on the top left, then click on Folder and search options, then click on the View tab and click on the Show hidden files, folders and drives radio button.

  • On a Mac OS:

    • Open a Terminal (via Spotlight: press CMD + SPACE, type terminal and press Enter) and run:

      defaults write com.apple.finder AppleShowAllFiles 1 && killall Finder
      

      Note: The keyboard shortcut to show hidden files in Finder is CMD + SHIFT + . so it is no longer necessary to modify the finder config this way

    • You could also type cd (the space is important), drag and drop your git repo folder from Finder to the terminal window, press return, then type rm -fr .git, then return again.

  • On Ubuntu, use shortcut Ctrl + H.

查看更多
放我归山
4楼-- · 2020-01-22 14:06

cd to the directory from which git need to be deleted and run command

Mac OS or any Linux distro

rm -rf .git
查看更多
Anthone
5楼-- · 2020-01-22 14:12

I just collect the ones which work best for me:

cd <repository-name>
find . -type f | grep -i "\.git" | xargs rm
cd ..
rm -rf <repository-name>
mkdir <repository-name>
cd <repository-name>
git init
查看更多
家丑人穷心不美
6楼-- · 2020-01-22 14:14

You can create an alias for it. I am using ZSH shell with Oh-my-Zsh and here is an handy alias:

# delete and re-init git
# usage: just type 'gdelinit' in a local repository
alias gdelinit="trash .git && git init"

I am using Trash to trash the .git folder since using rm is really dangerous:

trash .git

Then I am re-initializing the git repo:

git init
查看更多
叛逆
7楼-- · 2020-01-22 14:15

Go to the git repository from git bash and type rm -rf .git

查看更多
登录 后发表回答