German police have used water cannons and pepper spray to disperse protesters in Hamburg after being attacked with bottles and stones by some marchers protesting the G20 summit.