Delete all Git Commit History

删除回忆录丶 提交于 2021-02-17 08:55:51

问题


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

回答1:


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



回答2:


You can use git merge --squash to squash all commits into one and then push it.




回答3:


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.



来源:https://stackoverflow.com/questions/14969775/delete-all-git-commit-history

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!