简体   繁体   中英

Delete all Git Commit History

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?

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

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.

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

您可以使用git merge --squash将所有提交git merge --squash为一个然后推送它。

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:

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM