Solution (source code)

= Solution

Again put $Y=\mathbb E[X\mid\mathcal G]$. For any fixed real $c$, the <random variable>
$$
D_c=|X-c|-\operatorname{sign}(Y-c)(X-c)
$$
is nonnegative and <integrable>. The <sign function> of $Y-c$ is bounded and $\mathcal G$-<measurable>, so conditioning and equality of the <probability distributions> give
$$
\mathbb E D_c=\mathbb E|X-c|-\mathbb E[\operatorname{sign}(Y-c)(Y-c)]=\mathbb E|X-c|-\mathbb E|Y-c|=0.
$$
Thus $D_c=0$ <almost surely>. On $\{Y>c\}$ this forces $X\geq c$; on $\{Y<c\}$ it forces $X\leq c$; on $\{Y=c\}$ it forces $X=c$. In particular $\{Y=c\}\subseteq\{X=c\}$ up to a null set. These two <events> have equal <probability>, again by equality of the <probability distributions>, so they agree up to a null set. Consequently
$$
\operatorname{sign}(X-c)=\operatorname{sign}(Y-c)\quad\text{almost surely}.
$$
Taking $c=0$ establishes the suggested sign assertion, but this alone would not exclude unequal positive values. Apply the same argument simultaneously to the <countable> set of rational $c$. Outside the union of their null sets, unequal $X$ and $Y$ would have a rational strictly between them, giving opposite signs. This proves the <conditional expectation preserving a distribution> result:
$$
\boxed{X=\mathbb E[X\mid\mathcal G]\quad\text{almost surely}.}
$$
Only <integrability> was used; no finite second moment or hidden square-integrability assumption is needed.