What Is a Hard Fork and How Can It Prevent a 51% Attack?
A hard fork is a radical change to a blockchain's protocol that makes previously invalid blocks and transactions valid, or vice-versa. In the context of a 51% attack, a hard fork can be used to switch to a new mining algorithm that is resistant to the attacker's hardware.
This would render the attacker's hardware useless and make it impossible for them to continue the attack. A hard fork can also be used to reverse the attacker's transactions, but this is a more controversial measure as it violates the principle of immutability.