How to undo rows of stitches

Hello again to some,

I was knitting a 22 stitch knit-purl-knit scarf and I was trying to knit in another ball of the same yarn. However, a chunk of the tail of the old yarn ripped off before I could knit it in.

I was nearly at the end of my row when I decided to do an emergency knit in of the 2nd ball of yarn.
By combining the tail of the first yarn and of the new yarn, I barely knitted and purled my way onto the new row. Unfortunately, I was forced to knit the last stitch (it should be purled).
I continued to knit and purl the next row. Then I discovered that though I knit-purl-knit the 22 stitches like usual, the knits and purls have switched places in my scarf.

How can I switch back the places of my knits and stitches?
Should I undo the rows of stitches through tinking?
(That would be hard considering that I had to add another ball of yarn at my mistake point so it might come unraveled. It was a very thin, nearly dead and wispy tail that I barely used. Should I go before that point and add in the yarn when the tail was longer and stronger?)

Thank you in advance.

If it’s just a row or two, you can tink back. If it’s more than that, I would take out the needle, rip back and then tink the last row as you put it back onto the needle. It may be just as well to work back to the mistake because you can correct the problem with the shortened tail. One of the most disappointing things is to finish a piece and wish you had corrected an earlier error.