代码之家  ›  专栏  ›  技术社区  ›  Priyank Bolia

如何重置远程GIT存储库以删除所有提交?

  •  145
  • Priyank Bolia  · 技术社区  · 16 年前

    如何重置远程和本地Git存储库以删除所有提交?

    我想从现在的头开始,作为最初的承诺。

    3 回复  |  直到 5 年前
        1
  •  392
  •   Lilith River    11 年前

    1. 删除 .git

    2. 重新创建git Repository:

      $ cd (project-directory)
      $ git init
      $ (add some files)
      $ git add .
      $ git commit -m 'Initial commit'
      
    3. 推送到远程服务器,覆盖。记住你这样做会把其他人搞得一团糟你最好是唯一的客户。

      $ git remote add origin <url>
      $ git push --force --set-upstream origin master
      
        2
  •  7
  •   Community Mohan Dere    9 年前

    首先,按照中的说明进行操作 this question 将所有内容压缩为一次提交。

    $ git push origin +master
    

    并可以选择在本地和远程删除所有其他分支:

    $ git push origin :<branch>
    $ git branch -d <branch>
    
        3
  •  3
  •   Konstantinos Nikoloutsos    6 年前

    在做任何事之前请 留一份 (安全总比遗憾好)

    git checkout master
    git checkout -b temp 
    git reset --hard <sha-1 of your first commit> 
    git add .
    git commit -m 'Squash all commits in single one'
    git push origin temp
    

    完成此操作后,可以删除其他分支。

    结果:您将拥有一个只有2次提交的分支。

    使用 git log --oneline 以最简单的方式查看您的提交,并找到提交的SHA-1!