我想保留本地提交历史作为自己的教学课程,但由于其尴尬的性质和明显的错误,因此将它们从远程存储库中删除。
我知道要删除can be done两端的所有当前提交,但是想知道是否有可能保持本地历史记录完整,并使远程存储库的提交从当前提交开始,然后照常跟踪本地提交
答案 0 :(得分:0)
一个选项是创建一个新分支以保留本地历史记录,在旧分支上重写历史记录并强制推送。然后,您的本地历史记录将被保留,而远程历史记录将被覆盖。
# Assume you are currently on the master branch
git checkout -b archived_master
git checkout master
git reset --soft <sha_of_very_first_commit>
git commit --amend -m 'This is the commit for the new remote history'
git push -f