删除所有 Git 提交历史记录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14969775/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Delete all Git Commit History
提问by noway
I am trying to fetch a repo from Github, revert a tag in past, push it to another remote with deleting all history. I can do everything with below except deleting all commit logs. What I am missing?
我试图从 Github 获取一个 repo,恢复过去的标签,将它推送到另一个远程并删除所有历史记录。除了删除所有提交日志之外,我可以使用下面的所有内容。我缺少什么?
git clone https://github.com/user/user-repo.git
cd user-repo
git reset --hard tags/v2.0
git remote add stash ssh://git@myserver:7999/myproject/user-repo.git
git push --force stash master
回答by pktangyue
I thought what you want is a repo like a new one, so deleting the .git/
directory and re-initing it will be more simple.
我以为你想要的是一个像新的 repo,所以删除.git/
目录并重新初始化它会更简单。
git clone https://github.com/user/user-repo.git
cd user-repo
git reset --hard tags/v2.0
rm -rf .git/
git init
git add .
git commit -m 'first commit'
git remote add stash ssh://git@myserver:7999/myproject/user-repo.git
git push --force stash master
回答by wRAR
You can use git merge --squash
to squash all commits into one and then push it.
您可以使用git merge --squash
将所有提交压缩为一个,然后推送它。
回答by Wil Cooley
Are you basically talking about rolling up all of the commits into one commit or do you want to retain all of the commits but truncate the actual commit message?
您基本上是在谈论将所有提交汇总到一个提交中,还是要保留所有提交但截断实际提交消息?
To squash the commits into one (and truncate the final commit message, if you want), you can use an interactive rebase:
要将提交压缩为一个(并截断最终提交消息,如果需要),您可以使用交互式 rebase:
git rebase -i <whatever>
To truncate the actual commit messages but retain all of the commits, use the --msg-filter
option to git filter-branch
.
要截断实际提交消息但保留所有提交,请使用--msg-filter
选项git filter-branch
.