Gitlab-delete commit history

This article will teach how to delete the commit history on Gitlab.

Step 1: remove all history (Make sure you have backup, this cannot be reverted)

rm -rf .git

Step 2: reconstruct the Git repo with only the current content.

git initgit add .git commit -m "Initial commit"

Step 3: push to GitHub.

git remote add origin <github-uri>git push -u --force origin master

And then, if you get the message:

remote: GitLab: You are not allowed to force push code to a protected branch on this project.

It's meaning your master had been protected, go to settings chick Repository and you will see the view below.

http://img2.58codes.com/2024/20112288kd6mgkx5Vt.jpg

Find the master and choose Unprotect.

http://img2.58codes.com/2024/20112288yLN9KIM5Ry.jpg

Then, try to push again if it can work your will only see the commit 'Initial commit' on your history.

http://img2.58codes.com/2024/20112288kEoGX7lmJ4.jpg

Finally, remember to protect master if you success to delete history.

http://img2.58codes.com/2024/20112288MMZiWgi6I7.jpg


关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章