For testing and bugs - A lot of notes! I take notes every day to help me remember where I was when I log back in the next day or after the weekend or PTO. I document every change I made in the ticket when I finish it, often with file names and even lines. Leaning on a version control GUI like Sourcetree helps as well.
For writing the new code - Document exactly how what you're changing behaves before you change anything. I appreciate when QA sends me videos of bugs. It helps a lot. Make small, manageable changes and test. Repeat. Discuss with your team (especially QA - they know how to break things) and brainstorm what workflows could possibly be affected. Be prepared for unexpected consequences. I cannot praise my QA team and our automated suite of end to end testing enough.