كتاب المغازى
64  
Military Expeditions led by the Prophet (pbuh) (Al-Maghaazi)
(35)
Chapter: The Ghazwa of Al-Hudaibiya
(35)
باب غَزْوَةِ الْحُدَيْبِيَةِ
Sahih al-Bukhari 4184

Narrated Nafi`:

Ibn `Umar assumed Ihram and said, "If something should intervene between me and the Ka`ba, then I will do what the Prophet (ﷺ) did when the Quraish infidels intervened between him and (the Ka`ba). Then Ibn `Umar recited: "You have indeed in Allah's Messenger (ﷺ) A good example to follow." (33.21)

حَدَّثَنَا مُسَدَّدٌ، حَدَّثَنَا يَحْيَى، عَنْ عُبَيْدِ اللَّهِ، عَنْ نَافِعٍ، عَنِ ابْنِ عُمَرَ، أَنَّهُ أَهَلَّ وَقَالَ إِنْ حِيلَ بَيْنِي وَبَيْنَهُ لَفَعَلْتُ كَمَا فَعَلَ النَّبِيُّ صلى الله عليه وسلم حِينَ حَالَتْ كُفَّارُ قُرَيْشٍ بَيْنَهُ‏.‏ وَتَلاَ ‏{‏لَقَدْ كَانَ لَكُمْ فِي رَسُولِ اللَّهِ أُسْوَةٌ حَسَنَةٌ‏}
Reference : Sahih al-Bukhari 4184
In-book reference : Book 64, Hadith 224
USC-MSA web (English) reference : Vol. 5, Book 59, Hadith 498
  (deprecated numbering scheme)