You'll find this most wonderful 'but' in Genesis 6. Reading the beginning of this chapter really makes it look like even if God knew the future, he did not know what sin would feel like. He felt regret.
But Noah changed that by being who he was. The rest they say is history . . . this has to be one of the best Bible buts.