Anas bin Malik reported,

The Prophet ﷺ went out one cold morning while the Muhajirun and the Ansar were digging the trench. He said, "O Allah, true goodness is the goodness of the Hereafter, so forgive the Ansar and the Muhajirun."They answered, "We are the ones who pledged allegiance to Muhammad to strive in jihad as long as we live."

Bukhari 7201

Sahih

حدثنا عمرو بن علي حدثنا خالد بن الحارث حدثنا حميد

عن أنس رضي الله عنه

خرج النبي ﷺ في غداة باردة والمهاجرون والأنصار يحفرون الخندق فقال اللهم إن الخير خير الآخره فاغفر للأنصار والمهاجره فأجابوا نحن الذين بايعوا محمدا على الجهاد ما بقينا أبدا

البخاري 7201صحيح
Contents
Reference
Commentary
Ayat
Collection
Sahih Bukhari
Book
Rulings
Chapter
How the imam takes the pledge of allegiance from the people
Numbering
Darussalam 7201
Bukhari 7201