Kadgiko Kadgiko - 3 months ago 19
Git Question

Git delete second repository and history

I believe I copy pasted a git project content (edit) B. In the folder of my project A. After some testing and modification I deleted the git project B, and the remote it added. But all the commits history are still shown in my project A.

  • How do I delete everything except what was in my original project?


  • When I do git branch -av, I only see the branch from project A which is good.

  • When I do git remote, I only see origin which is good (I deleted the project B - origin)

  • When I show all branches, I see commits of both projects.

  • No commits have been merged from project A to B or vise-versa. (I can see in sourcetree that both project never crosses each other.

  • In the .git folder, I can see SHA in the log and refs dans that do not belong to project A.

I don't know what I have done exactly to end up with this state...


Example for the folder paths:







When you copy-pasted B into A git repo, you created a nested git repo.
That means, each time B had a new commit, A recorded the new B SHA1 as a gitlink (special entry in A index).

When you remove B, you add and commit that deletion in A (to record the deletion of the gitlink B).

But the history of A would still have all the instances where B was modified in A history (since B gitlink would change each time B has a new commit of its own).

To fully remove B from A history, you would need git filter-branch (to rewrite A history)

Something like:

git filter-branch --force --index-filter \
  'git rm --cached --ignore-unmatch PATH-TO-B' \
   --prune-empty -- --all

In the OP Kadgiko's case, after discussion, it appears that:

  • The repo B was copied over A (resulting in a mixed .git content)
  • it looks like the changes have been transferred to the remote A (so no cloning possible).

The conclusion was:

Alright, will create a new project and just start from there, this is a relatively new project and it won't be much trouble if we lose the last 100s commits.