1

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

Obito
  • 391
  • 3
  • 8
Kadgiko
  • 355
  • 3
  • 14

1 Answers1

0

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.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • The parameter PATH-TO-B, is the the original path or the copied folder path? – Kadgiko Oct 05 '16 at 15:35
  • It is the folder B in the repo A – VonC Oct 05 '16 at 15:36
  • I currently have multiple folder for the project B, both A and B have the same root. So the root would be somthing like (see edited answer for formmating). The project B is not fully nested in A to have something like C:\GitRepo\ProjectA\ProjectB – Kadgiko Oct 05 '16 at 15:49
  • @Kadgiko have you or have you not copied *one* repo into *one* other repo? – VonC Oct 05 '16 at 15:55
  • From what I understand I guess I didn't, sorry i didn't realized the difference sooner, I did copy all the __content__ of the repo B into repo A. Is it possible that the 2 .git folder got merged even if they where hidden? – Kadgiko Oct 05 '16 at 15:59
  • @Kadgiko no, not possible: the content of B/.git would have overridden A\.git. Resulting in A "seeing" B history. – VonC Oct 05 '16 at 16:04
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/125012/discussion-between-kadgiko-and-vonc). – Kadgiko Oct 05 '16 at 16:17
  • @Kadgiko OK, I have included your conclusion in the answer for more visibility. – VonC Oct 05 '16 at 20:21