Since Judas knows where Jesus usually spends time on the Mount of Olives, he is able to easily lead a group to capture Him. He identifies Jesus to the others by greeting Him with a kiss, a common greeting at the time. It seems Jesus stops him, but I read the situation as very confused and fast-paced.
Jesus’s disciples figure out what all these armed men are here to do and ask Jesus if they should try to fight back. They’ve got these swords after all. Without waiting for the answer, Peter (as we know from other accounts), the brash, impulsive one, goes ahead and swings at a bondslave of the high priest. This man may have been in charge of the group of guards following Judas, and Peter may have recognized him as the leader and so target him first. Or maybe he was just the closest person.
In any case the high priest’s slave loses his ear from Peter’s strike, so I presume Peter was going for the kill. In light of that, I’m really surprised things didn’t devolve into a mêlée. On the other hand, Jesus doesn’t want that to happen, therefore it doesn’t. Instead, Jesus heals the man’s ear and talks the crowd that has come to arrest Him. He points out that they aren’t not acting in righteousness, and they know it, because they are operating in secret, away from public view.
Let us not react in anger and selfishness, but to listen to Your voice in all circumstances.