
This is a bit complicated. The main theory on the creation of the Torah or Pentateuch is the Documentary Hypothesis. Basically, it is thought that these first five books are a combination of 4 sources and possibly a 5th editor. The sources are J, E, P, and D, with some adding an R source. J is the Jehovah or Jahwist source (they used the term Yahweh for God. Jehovah is the transliteration of the term to German, and then English speakers, not realizing how it should be pronounced based on the German language, bastardized it.)
E is the Elohim or Elohist source as he called God Elohim. P is the priestly source as they were most like a priest and were more concerned about that aspect.
D is the Deuteronomist source, which is named for the book Deuteronomy.
R is the redactor who edited the works together and added a bit as well. There may be another editor as well who cleaned it up.
These sources can be picked out quite well, and it explains why there are multiple tellings of the same stories.
These sources would have been known early on, especially as some were based in specific geographic areas. J and E, for instance, were most likely court writers, one for the northern kingdom and the other for the southern kingdom.
These works would have circulated independently for decades if not centuries. It wouldn’t be until much later that the Torah, as we know it, was compiled. And even then, it wasn’t attributed to Moses. That occurred more towards the end of the Babylonian captivity, when they were regrouping and were looking at their cultural heroes.
While Moses would largely then be attributed as the author, there were scholars who rejected that notion. But when modern Biblical scholarship began in the 1800s, the idea that Moses was the author had been ignored and the Documentary Hypothesis came out.
