Turn off the water supply valve that runs to the heater.
Remove the water pipe from the fitting on the heater -- and the fitting from the wall -- by using a wrench. If the pipe is stuck, tap the fitting with a hammer to loosen the grip.
Slide the water pipe out from both fittings.
Measure the distance from the wall to the heater and cut, or purchase, a new piece of pipe that will fit the distance.
Insert the piping into both fittings.
Tighten the fittings by using the wrench.
Apply a waterproof sealant around the fitting to prevent leaks. Read the directions on the sealant and use as directed.
Turn the water supply valve back on and inspect the area for leaks.