2013-02-19 163 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