The song was first recorded in 1924, first mentioned (apparently) in 1914 (having been heard in the Great Smoky Mountains ca1905).
Beyond that, there's no telling when the tune appeared or when the Civil War lyrics were first sung. Not every version has them.