  Let $\Sigma$ be a compact oriented surface. The Dehn twist along every simple
closed curve $\gamma \subset \Sigma$ induces an automorphism of the fundamental
group $\pi$ of $\Sigma$. There are two possible ways to generalize such
automorphisms if the curve $\gamma$ is allowed to have self-intersections. One
way is to consider the `generalized Dehn twist' along $\gamma$: an automorphism
of the Malcev completion of $\pi$ whose definition involves intersection
operations and only depends on the homotopy class $[\gamma]\in \pi$ of
$\gamma$. Another way is to choose in the usual cylinder $U:=\Sigma \times
[-1,+1]$ a knot $L$ projecting onto $\gamma$, to perform a surgery along $L$ so
as to get a homology cylinder $U_L$, and let $U_L$ act on every nilpotent
quotient $\pi/\Gamma_{j} \pi$ of $\pi$ (where $\Gamma_j\pi$ denotes the
subgroup of $\pi$ generated by commutators of length $j$). In this paper,
assuming that $[\gamma]$ is in $\Gamma_k \pi$ for some $k\geq 2$, we prove that
(whatever the choice of $L$ is) the automorphism of $\pi/\Gamma_{2k+1} \pi$
induced by $U_L$ agrees with the generalized Dehn twist along $\gamma$ and we
explicitly compute this automorphism in terms of $[\gamma]$ modulo
${\Gamma_{k+2}}\pi$. As applications, we obtain new formulas for certain
evaluations of the Johnson homomorphisms showing, in particular, how to realize
any element of their targets by some explicit homology cylinders and/or
generalized Dehn twists.
