Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
349 views
in Technique[技术] by (71.8m points)

Delete all files and history from remote Git repo without deleting repo itself

I would appreciate it if someone could tell me how I could delete every single file/folder on my git repository without actually deleting the repository itself. I want to delete all history associated with those files as well.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As I explain in this answer to Delete or remove all history, commits, and branches from a remote Git repo?, you can also achieve the same thing as Ceilingfish's answer (i.e. delete all references/branches/tags in the remote repo) by doing the following:

  1. Create new empty repo with initial commit:

    mkdir new
    cd new
    echo "This is the README" > README.md
    git init
    git add .
    git commit -m "Add README.md (initial commit)"
    
  2. Add remote repo as origin:

    git remote add origin <url-to-remote>
    
  3. Mirror push to remote:

    git push origin --mirror
    

That will delete all references/branches/tags in your remote repo, and any dangling commits will probably be garbage collected eventually. From the official Linux Kernel Git documentation for git push (emphasis mine):

--mirror

Instead of naming each ref to push, specifies that all refs under refs/ (which includes but is not limited to refs/heads/, refs/remotes/, and refs/tags/) be mirrored to the remote repository. Newly created local refs will be pushed to the remote end, locally updated refs will be force updated on the remote end, and deleted refs will be removed from the remote end.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...