문제

I have created a branch where I was trying an approach to a problem which didn't work out, so I want to delete the branch, including all commits I made on it. For the sake of the argument, my branches look like this (when viewed with Gitk):

A--B--C--D Master
    \
     \-E-F Unwanted

I want it to look like this:

A--B--C--D Master

If I delete the Unwanted branch I end up with this instead:

A--B--C--D Master
    \
     \-E-F

I have no use for commits E and F, and don't want them cluttering my Git history.

Apologies for what may seem to be a very simple (and possibly stupid) question, but I've been unable to find a suitable answer elsewhere.

도움이 되었습니까?

해결책

No, that's all you do. As long as E and F aren't referenced in any branch or tag, they'll eventually be garbage collected. I assume you're looking at it in gitk and still see the commits hanging out. If you restart gitk or do a forced reload with Ctrl+F5, they'll disappear. They're still there, but git will take care of them eventually. While you can force them to be cleaned up immediately, that's not a good habit to get into. The default time-to-live of 2 weeks for orphaned commits is there because just sometimes you really did want those commits, and you just didn't know it yet, so leave them orphaned and move on.

다른 팁

If you run git gc it will remove unreferenced branches (which F is, assuming you didn't tag it or derive other branches from it) when they are older than a certain threshold (2 weeks default, and you can adjust it with --prune=<date>).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top