2013-02-19 170 views
15

我想从Github获取一个回购,在过去恢复标签,将其推到另一个远程,删除所有历史记录。除了删除所有提交日志之外,我可以用下面的方法做所有事我错过了什么?删除所有Git提交记录

git clone https://github.com/user/user-repo.git 
cd user-repo 
git reset --hard tags/v2.0 
git remote add stash ssh://[email protected]:7999/myproject/user-repo.git 
git push --force stash master 

回答

33

我以为你想要的是一个像新的回购,所以删除.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://[email protected]:7999/myproject/user-repo.git 
git push --force stash master 
+0

谢谢,这就是我在阅读你的文章之前结束了。我做了完全一样的东西:) – noway 2013-02-20 09:02:30

+0

这非常帮助我!谢谢 – breezy 2016-02-16 17:42:19

+0

这就是我想要的。 – Shaowu 2016-06-23 06:02:32

3

您可以使用git merge --squash将所有提交压缩为一个,然后按下它。

1

你基本上是在谈论将所有提交汇总到一个提交还是你想保留所有的提交,但截断实际的提交消息?

压制该提交到一个(和截断最后提交信息,如果你想),你可以使用一个交互式的rebase:

git rebase -i <whatever> 

要截断实际提交信息,但保留所有提交的,请使用--msg-filter选项git filter-branch