William R. Gerhart was born on January 10, 1844, in Gettysburg, Pennsylvania, to Emanuel and Eliza Gerhart. His father was a minister who served as president of the Lancaster Reformed Theological Seminary and Franklin and Marshall College. The family lived in Gettysburg until the late 1840s, when they moved to Cincinnati, Ohio. They moved to Lancaster, Pennsylvania, in the 1850s, and he attended Franklin and Marshall College.
He served as a 2nd lieutenant in the 6th Pennsylvania Militia Infantry from September 15, 1862, until September 28, 1862. Gerhart graduated in 1863, and he returned to the Union army soon afterward. He enlisted on July 2, 1863, and he mustered in as a sergeant in Independent Battery I of the Pennsylvania Light Artillery. He was promoted to 2nd lieutenant on August 26, 1863, and he mustered out on January 7, 1864. He returned to the Union army later that year, mustering in as a major in the 121st USCT Infantry. Army officials transferred him to the 125th USCT Infantry in June 1865, and he eventually became colonel of the regiment. He mustered out on December 20, 1867.
Gerhart returned to his father’s household in Lancaster after the war, and he earned a living as a civil engineer. He supported the Republican Party, and he became a prominent member of local society. He married Ella Carpenter in 1882, and the couple had no surviving children. He died of apoplexy in Lancaster on August 6, 1906.