删除git远程仓库所有提交记录 how to delete all commit history in github?
操作如下
1 | 切换到一个全新主分支,无所谓叫什么,后面还会修改分支名称 |
语句解释
orphan
What is git checkout --orphan used for?
The core use for git checkout –orphan is to create a branch in a git init-like state on a non-new repository.
Without this ability, all of your git branches would have a common ancestor, your initial commit. This is a common case, but in no way the only one. For example, git allows you to track multiple independent projects as different branches in a single repository.
That’s why your files are being reported as “changes to be committed”: in a git init state, the first commit isn’t created yet, so all files are new to git.
git -A
git-add
这个命令会将当前目录下包括子目录下所有改动的文件提交到暂存区。
git branch -D
--delete --force的快捷方式。强制删除
git branch -m
Move/rename a branch, together with its config and reflog.
git push -f
删除一次提交记录
删除最后一次提交
第一步:回滚上一次提交
1 | git reset --hard HEAD^ |
第二步:强制提交本地代码
1 | git push origin master -f |
删除指定commit提交(非最后一次提交)
查看提交记录,确定需要删除记录的前一次提交ID ,这里是 5606512
1 | ✗ git log --pretty=format:"%h | %ai | %an | %s" | head -n 40 |
执行
1 | git rebase -i 5606512 |
执行交互
必须要删除的 commit 前面的 pick 改为 drop , vim 保存退出。
提示冲突解决冲突,之后执行
1 | ✗ git add . |
就成功了。
ps. 如果直接push
1 | ! [rejected] master -> master (non-fast-forward) |
看下git log
1 | ✗ git log --pretty=format:"%h | %ai | %an | %s" | head -n 40 |
ps. github给出的解决方案
Removing sensitive data from a repository