Sometimes it is handy to to be able to undo in just a specific region. You have done a lot of editing and the code broke in a specific function which of course used to work…
The trick is to do C-<space> in the beginning of the function and moving down to the end of the function and pressing C-u C-_ to undo changes only in the region you have marked.