Use the Xcode report navigator.
To show the report navigator, either (1) click the rightmost button in the navigator bar at the top of the navigator area, which is on the left side of the workspace window, (2) select View > Navigators > Reports from the menu bar at the top of the screen, or (3) press ?9.
The report navigator shows a list of recent builds. Select one to see the details of the build in the editor area, which is in the center of the workspace window.
At the top of the editor area, make sure "All" and "All Messages" are both selected. Then click the "Export…" button at the top-right of the editor area to export a text file containing all the messages and build commands.
If you just want to see the messages and build commands for a specific build step, then select that step and click the small button on the right with a series of horizontal lines.
The picture below is from the original answer.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…