They action isn't necessarily invariant, is it? If it changes by a total time derivative of G the action will change by the difference of G at the two endpoints, the reason this is still a symmetry is that you don't change the endpoints when considering variations of the trajectory in the Lagrangian formalism. g