如何清除git历史记录中的所有先前提交?
我最近开始了一个新项目,并且在开始时做了很多实验.现在有一些新成员加入,我的想法是从git历史记录中删除第一次提交,因为它们似乎毫无意义,而且浏览该repo的每个人都可能会感到困惑.
I have started a new project recently, and I've made a lot of experiments at it's beginning. Now some new people are joining, and I have an idea of wiping the first commits away from git history, because they seem to make no sense and everyone browsing the repo can get confused.
一个可能的解决方案是从头开始建立一个新的仓库,但是我更愿意重写历史记录.
A possible solution is setting up a new repo from scratch, but I would prefer rewriting the history.
我需要的只是将master上的HEAD提交设置为仓库中的第一个也是唯一的提交.
What I need is just setting the HEAD commit on master to be the first and only commit in the repo.
If you want to use git rebase
you might be interessted in Git - squash entire branch - one line squash command.
如果您有很多提交的历史记录,则git rebease
可能会花费很长时间.在这种情况下,您可以制作一个浅表克隆
If you have a history with a lot of commits, git rebease
might take a long time. In this case you can make a shallow clone
git clone --depth 1 <REPO_URL>
比做
git commit --amend
为了创建一个包含最新更改的独立提交 而不是强制推送
in order to create an independent commit that contains the latest changes and than do a forced push
git push -f