Use this phrase when you regret something. It means that you would like to change what happened in the past.
Of course, it's not possible to change the past, so you use the word "wish" in this sentence. A lot of English learners mix up the words "wish" and "hope". Use "wish" for imaginary things that you don't think can happen:
I wish I was a little bit taller.
Use "hope" to talk about things that might still happen:
I hope I get a raise this year.
When you're using "wish", you're talking about something not real so the tense changes. When you're talking about something that might happen in the future with "hope", it looks like this:
I hope you can come!
But if someone tells you that they can't come, you can tell them:
I wish you could come!
"Wish" uses what looks like the past tense of the verb (although it's not really past tense; it's the "unreal" aspect) when talking about the present or the future. When you're talking about something in the past with "wish", you use "I wish (someone) had...":