I've found in the past that I'd written out a short test script to prove a theory or see how a subroutine would work, then I'd change the script and lose what I'd done before. A couple of days later I'd be working on something and think "I've done this before in a test script" go to look for it, and realize I'd deleted that section, or changed it too drastically.
To solve this I've created two repositories one for documentation and the other for test scripts. I treat them just as I do any other programming project. Issue resoloved. I don't know why I hadn't thought of doing this before.