When birds fly at or peck at a reflection in a window or car mirror, it's important to understand something else is at work.
Birds don’t see a reflection; they see an intruder. They can spend hours flying at this illusion, determined to drive away "the other bird." The most common songbird species that attack their reflections (and your windows) are Northern Cardinals, American Robins, bluebirds, towhees, sparrows and sometimes mockingbirds.
These repeated attacks on your windows can be annoying. You may also be concerned the bird will get hurt, or get distracted from more important tasks, like incubating eggs and feeding hatchlings.
Why do they do this?
Their preoccupation with "the other bird" is very much connected to the time of year. You might say from winter to spring, the birds have changed their personalities. In the spring, a burst of hormones flood their brains, so they disband from their winter flocks and enter a new mindset, all centered around mating and nesting. What you have is a neighborhood of amped-up birds motivated to protect their mates, nests and territories.
What can you do?
Most of the time, these bumps into the hard glass will not injure the bird, since they are not flying with great velocity. In all, this behavior will come to an end in a few days or even weeks. However, you can try a number of things to make the bird's “enemy” disappear and help them move on.
For car mirror attacks, the solution might be as simple as moving your car. Or, you can find a way to cover the mirrors while parked. As an example, plastic grocery bags work, tied over the side-view mirrors (just don't forget to remove them before you pull away!)
For window reflection attacks, the goal is to minimize the reflection and there are several ways to achieve this. If you have screens and they are not in, install them. Or, direct a bright light out the window. Another great option if you don't care about the view, temporarily soaping the windows with bar soap may also work. Finally, you can simply use transparent tape or window alert decals (found online) and apply to the outer surface of the window to help cut down on reflection.