Ibn Mughafal reported,

The Messenger of Allah ﷺ ordered that dogs be killed, but then he said, "What is the matter with them and with the dogs?" He then granted an exemption for the hunting dog and the sheepdog. Ibn Hatim, in his version of the report from Yahya, said, "He granted an exemption for the sheepdog, the hunting dog, and the dog that guards crops."

Muslim 4022

Sahih

و حدثنيه يحيى بن حبيب حدثنا خالد يعني ابن الحارث ح و حدثني محمد بن حاتم حدثنا يحيى بن سعيد ح و حدثني محمد بن الوليد حدثنا محمد بن جعفر ح و حدثنا إسحق بن إبراهيم أخبرنا النضر ح و حدثنا محمد بن المثنى حدثنا وهب بن جرير كلهم عن شعبة بهذا الإسناد و قال ابن حاتم في حديثه عن يحيى ورخص في كلب الغنم والصيد والزرع

مسلم 4022صحيح
Contents
Reference
Commentary
Ayat
Collection
Sahih Muslim
Book
Sharecropping of orchards
Chapter
Command to kill dogs, its abrogation, and the prohibition of keeping them except for hunting, farming, livestock, and similar purposes
Numbering
Darussalam 4022
Muslim 4022