fwiw, yes, a knife can be useful if you know how to use it and have ice blood to remain calm - a simple walking stick (or pepper spray) is 100% better in every way - keeps distance, and it will bite the stick instead of you, and a few good kicks will end most attacks
if you don't have a walking stick, the best way to deal with a dog that is actively attacking is make a fist with your jacket sleeve or heavy leather/canvas workgloves (working on a fence right?), stick it out in front of you & when the dog bites, keep pushing your fist to the back of it's throat
your other hand can then easily punch its sensitive nose, which should make them disengage most times...
if it's a crazy attack breed, you may have to use your other arm to choke it out or get around it and force its neck back (nose pointing to the sky) if it has a collar, grab it with your other hand from behind and twist; very effective choke which will make even the most crazy dog pass out pretty quickly
if there is no collar, headlock it with your free arm & squeeze the carotid artery to try for the same result
I do not recommend anyone go hand-to-hand vs an attacking dog, but if you're forced into it, this approach is better than most