简体   繁体   English

Gitlab删除旧提交

[英]Gitlab remove old commits

I have cloned a repo from gitlab. 我从gitlab克隆了一个回购。 Without removing the .git folder i have worked and edited the cloned project and done certain commits.Now my gitlab has old commits as well as my commits .Is there any way to remove old commits and maintain my commits only.?Thanks 没有删除.git文件夹我已经工作并编辑了克隆项目并完成了某些提交。现在我的gitlab有旧提交以及我的提交。有没有办法删除旧提交并仅维护我的提交。谢谢

What you can do is create a new empty repo, and import in it only your new commits from your current (mixted) repo. 你可以做的是创建一个新的空仓库,并从中导入当前(混合)仓库中的新提交。

cd /another/local/path/aNewFolder
git init .
git remote add mixtedRepo /path/to/mixted/repo
git fetch mixtedRepo

So far, your new repo is empty, and there is a mixtedRepo/master remote branch in it (with old and new commits). 到目前为止,您的新repo是空的,并且其中有一个mixtedRepo/master远程分支(使用旧的和新的提交)。

Let's make sure you have a local master branch first: 让我们先确保你有一个本地主分支:

git commit --allow-empty -m "master branch"

Then, let's rebase on your lone empty commit the commits you did in your old repo: 然后,让我们在您的旧回购中提交您的单独空提交中的提交:

git rebase --onto master <your First New Commit SHA1> mixtedRepo/master

Finally, let's push that to a new remote GitLab repo: 最后,让我们将其推送到一个新的远程GitLab仓库:

git remote add origin /url/new/empty/GitLab/repo
git push -u origin master

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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