简体   繁体   中英

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?

Observations:

  • 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...

Comments:

Example for the folder paths:

C:\\gitRepo\\ProjectAB\\

C:\\gitRepo\\ProjectAB\\ProjectA-1...

C:\\gitRepo\\ProjectAB\\ProjectA-2...

C:\\gitRepo\\ProjectAB\\ProjectB-1...

C:\\gitRepo\\ProjectAB\\ProjectB-2...

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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