2

Some time ago I pulled into my project stuff from an external repository. I'm not actually sure of what I did - I wanted to try out this framework by merging it into my project, so I did something and I cannot remember what exactly anymore.

So, after some time I decided that was not a good idea and undid the merge. This left me with a weird tree structure. How can I just remove the lower, dangling commit thread? (They are actually mostly public tags of the external repository)

user1846231
  • 315
  • 3
  • 12

2 Answers2

2

The 'weird tree structure' is a branch. You can remove these with git branch -D branchname. However this will in essence unreference the commits, but not delete them totally (i.e. they will not appear as a tree, but will still be on your disk). If you want to garbage collect them, git reflog expire and git gc are your friends.

abligh
  • 24,573
  • 4
  • 47
  • 84
  • It is not a branch, at least I believe so, it's not listed among my branches. It is external code from another repository. So it doesn't have a branch name to perform `branch -D`, and `git gc` did nothing, as per the other comment. – user1846231 Jul 10 '15 at 19:49
  • 1
    How are seeing the 'weird tree structure' at the command line? if `git reflog expire` and `git gc` don't help, they must be referenced somehow. Perhaps by a tag? – abligh Jul 10 '15 at 20:13
  • 1
    Ah! I bet those are in the *remote* branches. Try `git branch -a` and see if you have remote branches that need deleting. – abligh Jul 10 '15 at 20:16
  • 1
    `git branch -a` shows four branches: develop, master, remotes/origin/develop, remotes/origin/master. Both remotes branches are written in red in my git bash console. The commit thread I want removed is full of tags, more than half the commits are tagged as version numbers for the framework I once wanted to use. – user1846231 Jul 10 '15 at 20:37
  • @user1846231 if you aren't using the remote branches, delete them. You can remote *all* your tags with something like `git tag | xargs git tag -d` - node that removes *all* your tags. You might need a `-f` too. – abligh Jul 10 '15 at 21:08
  • To clarify: I don't have any tags of my own. My project is on bitbucket, I assume the remote branches are the bitbucket branches, so I don't want to delete them. Is that right? – user1846231 Jul 10 '15 at 21:11
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/82998/discussion-between-user1846231-and-abligh). – user1846231 Jul 10 '15 at 21:12
1

Have a look here: Listing and deleting Git commits that are under no branch (dangling?)

Specifically, this answer:

git reflog expire --expire-unreachable=now --all
git gc --prune=now

Please read the full answer so you understand what you are doing to your repository.

Community
  • 1
  • 1
Eric
  • 673
  • 5
  • 18
  • 1
    I have tried what you said. From what I understand, the first command erases any log link that dangling thread might have, and the second one erases everything that is dangling. But these two commands have no effect, and I still have that external code showing in my repository. – user1846231 Jul 10 '15 at 19:48