How to remove the first commit in git?

后端 未结 9 1713
深忆病人
深忆病人 2020-12-07 07:20

I am curious about how to remove the first commit in git.

What is the revision before committing any thing? Does this revision have a name or tag?

9条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-07 07:30

    If you want to keep other branches, but for example make the master branch start anew without common history to other branches, one safe way to achieve this is to create a new repository, and push contents of that in your old one:

    cd ..
    git init newrepo
    cd newrepo
    # make some initial commits
    git push ../oldrepo master:newmaster
    

    This creates newmaster branch in the old repository, with history that is not common with any of the other branches. Of course, you can just overwrite the master as well, with git push -f.

    If you want to destroy all branches and all existing content, then just run

    rm -rf .git/
    

提交回复
热议问题