Nobody knows for sure, but for a while now the prevailing theory has been that the books of moses have an oral tradition behind them, and the books we have now are combinations of several different sources (usually called P,D,J,E, and R). You can read about these in the introductions to Genesis in most Bible commentaries (try the Interpreter's Bible or the New Interpreter's Bible). The person who actually compiled the sources is the "R" in the above five sources (redactor).
-Chris