You're almost certainly thinking of Ridley Scott's 2001 war film Black Hawk Down.
In a harrowing, extended sequence, U.S. Army Rangers and Delta Force operators are pinned down in the narrow streets of Mogadishu during the Battle of the Black Sea. As the firefight with Somali militiamen drags on, multiple soldiers exhaust their ammunition and are forced into desperate close-quarters combat—using knives, bayonets, entrenching tools, and bare hands.
While the film dramatizes and compresses events for narrative momentum, the scene reflects the brutal reality of urban warfare: when supply lines are cut and engagement distances collapse to zero, training and improvisation become the only weapons left.