SAN FRANCISCO Buster Posey had four hits, including a three-run double to help San Francisco break out of a collective funk, and the Giants beat the Milwaukee Brewers 8-5 on Sunday to avoid a four-game sweep.