The online redo log files contain the information necessary to replay a transaction, committed or not. Even uncommitted transactions can be written to the online redo log files. Before a commit is complete, the transaction information is written to the online redo log files. And changes to your rollback or undo segments are also written to the online redo log files. So in that sense, they also contain the information to undo a transaction.
Just because a transaction committed does not mean that the datafiles were updated. You may have committed transactions that are not yet represented in the database datafiles. So your assumption that a "datafile contains all the comitted transactions" is not correct. Eventually, the changes of a committed transaction will get written to the datafile. This happens when the database performs a checkpoint. However, updating the datafiles on every COMMIT is too costly in terms of I/O performance and can slow down the database performance. The only I/O required on COMMIT is to update the online redo log files. Should your system crash before the committed transaction's changes have been written to the database datafiles, the instance will peform recovery and use the information in the online redo log files to replay, or roll forward that committed transaction.