0

I created a new project by copying existing code. Normally, I'd clone a new empty repository, copy over the files (without the .git folder) from an existing similar project and delete any relavent files. The initial commit will be all the tooling/setup stuff with no content.

I've somehow messed this up - Our CI just tried to do a 1.0.0 release and failed becuase that tag already exists in git. It exists on the history of the project I coppied, which is somehow, disjointedly hanging out before the actual project commits:

enter image description here

The Initial Commit of the new project is a complete commit - i.e. it's not "on top" of the existing commits. It's not deleting files, just adding new versions. So the new and old history is completely disjointed.

No idea how I managed it!

What would be the best way to remove the old history, and it's tags? Should I just go through deleting tags manually?

Joe
  • 6,773
  • 2
  • 47
  • 81

1 Answers1

0

If no branches are referencing the old commits AND no tags are attached to the old commits AND your new initial commit is not a "child" commit of the old code(so it has no parent commit) all old commits are orphans.

In the screenshot it's visible there are still some tags attached to the old commits.

After deleting those tags (git tag -d TAGNAME && git push --delete origin TAGNAME) you can garbage-collect those old commits locally using git gc --prune=now --aggressive. You will probably also have to garbage-collect on the remote. Github according to this answer automatically periodically runs a gc. If memory serves me well, gitlab provides an option in the project settings. For other service providers, consult its manual on how to perform a git GC.

ikkentim
  • 1,639
  • 15
  • 30