Can I make git smarter when figuring out if it's okay to delete a branch?
git branch -d
is almost always wrong about if a branch has code I haven't merged. Very开发者_如何学Go often I'll have branched foo off of master, done work, and then merged it back into master, but then git branch -d
says "The branch 'foo' is not fully merged", until I merge master back into foo (which is sometimes a pain).
You should not have to merge something into foo to be able to delete foo.
As far as I experienced, the criterion is whether foo is merged into HEAD, so maybe you should make sure master is your current branch when trying to delete foo.
in this case it looks like i squashed
foo
's commits
That would be consistent with the "isn't fully merged" warning (branch with commits that are not reachable from any other ref head)
Two checks can be done:
1/ The "Git and “The branch 'x' is not fully merged
” Error" question is interesting:
git log --graph --left-right --cherry-pick --oneline master...foo
2/ See "Using Git, show all commits that are in one branch, but not the other(s)"
git branch --contains branch-to-delete
More than one branch should be returned
Do a
git rebase master foo
after you have merged everything. Then a git branch -d foo
should succeed
#!/bin/sh
# Get rid of all the branches I don't care about.
for b in $(git branch) ; do
git rebase master ${b}
if test $? -ne 0; then git rebase --abort ; fi
git checkout -f master
done
for b in $(git branch) ; do git branch -d ${b} ; done
精彩评论