How to reset a remote Git repository to remove all commits?

后端 未结 3 586
日久生厌
日久生厌 2020-11-30 16:09

How can I reset a remote and local Git repository to remove all commits?

I would like to start fresh with the current Head as the initial commit.

3条回答
  •  一生所求
    2020-11-30 16:44

    Were I you I would do something like this:

    Before doing anything please keep a copy (better safe than sorry)

    git checkout master
    git checkout -b temp 
    git reset --hard  
    git add .
    git commit -m 'Squash all commits in single one'
    git push origin temp
    

    After doing that you can delete other branches.

    Result: You are going to have a branch with only 2 commits.

    Use git log --oneline to see your commits in a minimalistic way and to find SHA-1 for commits!

提交回复
热议问题