George McEwen, 31, pleaded guilty to assaulting Joel Mannion to his severe injury at a house party in West Lothian.
The charge was reduced in seriousness after the prosecution accepted that Mr Mannion had not suffered permanent disfigurement or permanent impairment as a result of the attack in May 2018.
Livingston Sheriff Court heard that all the people at the party in Broompark Road, East Calder, had been on a drink and drug binge for most of the day.
She said Mr Mannion jumped to his feet to get between the two men and the accused struck him to the head with a hammer which had been lying on the floor.
Mr Mannion fell backwards onto the couch with blood pouring from a wound above his eye after which his recollection of the incident was “blurred”.
McEwen, who lived in Norman Rise in nearby Livingston, was seen leaving the house carrying the hammer.
A description of him was provided to the police but he was only arrested after an anonymous caller telephoned the confidential 101 number and identified him as being responsible for the assault.
Mr Mannion later picked out the accused’s image from a book of suspects, telling officers he was “100% certain” he was the attacker.
Miss Imrie said Mr Mannion was taken by ambulance to St John’s hospital in Livingston where his face was X-rayed and he underwent a CT scan.
He was found to have cracked bone in his skull above his right eye and a 0.5cm cut to his head was stitched. Doctors decided he did not require surgery and a subsequent examination showed he was making a good recovery.
He said the trouble started after Mr Watt made “threatening and abusive remarks” to his client and Mr Mannion jumped up seemingly to back up his friend.
He said McEwen felt threatened and completely over-reacted to the situation by picking up the hammer and attacking him.
Mr. Bann added: “I’m told that the blow was a glancing blow. Because of that somewhat fortunately the injury was not worse. That’s something my client is thankful about.
“He has expressed due shame and remorse and is genuinely contrite about this. He realises alcohol and drugs are at the root of his problems and since he’s been in custody he has engaged with a psychiatrist to properly understand the impact of drugs and alcohol on him.”
Sheriff Peter Hammond told McEwen: “It’s to your credit that you have taken steps to address these difficulties, however, this remains a very serious case.
“You pled guilty to assaulting a man by striking him on the head with a hammer.
“The outcome was a matter of chance, whether for better or for worse.
“The difficulty for you is you have two previous convictions for assault. In 2011 you were convicted of assault to injury and in 2017 of assault to severe injury and permanent disfigurement.
“I consider that custody is the only appropriate disposal. It’s clear you have a predisposition to violence and, factoring in alcohol and drugs with your mental health, the situation can deteriorate into a confrontation.
“In order to protect the public from serious harm on your release I am imposing a supervised release order so that you will be kept under supervision for a period of nine months.”
The sheriff backdated the 18-month prison sentence to 12 August, when McEwen was remanded in custody.