gpt4 book ai didi

git - 从远程 Git 仓库中删除所有文件和历史记录而不删除仓库本身

转载 作者:IT王子 更新时间:2023-10-29 00:44:31 25 4
gpt4 key购买 nike

如果有人能告诉我如何在不实际删除存储库本身的情况下删除我的 git 存储库中的每个文件/文件夹,我将不胜感激。我也想删除与这些文件关联的所有历史记录。

最佳答案

正如我在 this answerDelete or remove all history, commits, and branches from a remote Git repo? 中解释的那样,您也可以通过执行以下操作实现与 Ceilingfish's answer 相同的事情(即删除远程仓库中的所有引用/分支/标签):

  1. 使用初始提交创建新的空存储库:

    mkdir new
    cd new
    echo "This is the README" > README.md
    git init
    git add .
    git commit -m "Add README.md (initial commit)"
  2. 添加远程仓库作为源:

    git remote add origin <url-to-remote>
  3. 镜像推送到远程:

    git push origin --mirror

这将删除您的远程仓库中的所有引用/分支/标签,并且任何悬空的提交最终可能会被垃圾收集。来自 official Linux Kernel Git documentation for git push(强调我的):

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

关于git - 从远程 Git 仓库中删除所有文件和历史记录而不删除仓库本身,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5363857/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com