If you use the single transistor approach and your transistor is a MOSFET, and if you directly connect the +12V signal to the MOSFET's gate, you'll likely see large voltage spikes on the +5V logic side during each logic state transition on the 12V side.
EXAMPLE 1
Figure 1 shows the voltage at the drain pin of an IRF530N NMOS for the circuit topology shown in fig. 2, but without resistor R2, and with M1's drain connected directly to a digital input pin on the microcontroller. (n.b. For this discussion, assume the microcontroller's input pin circuit does not provide voltage clamping protection diodes.)
The preshoot pulses observed at the corners of the voltage signal at M1's drain pin (fig. 1) occur because the MOSFET capacitively couples the edge of each state transition on the +12V side through its gate-drain capacitance to to drain pin on +5V logic side. The amplitude of these voltage spikes can be large enough to damage the circuitry of the microcontroller's digital input pin. For example, if a microcontroller's digital input pin has a minimum rated input voltage of -0.5 V, and a maximum rated voltage of 5.5 V, the signal shown in fig. 1 approaches the -0.5 V minimum, and it clearly exceeds the +5.5 V maximum.
Figure 1.
There are various ways to manage this problem—e.g., see this EE.SE message thread: Schottky diodes or regular ones for input protection circuit.
Note that modern microcontrollers usually provide the two voltage clamping protection diodes shown in the linked page; they are part of the circuitry that implements a digital input pin. If this is the case, you provide resistor R2 connected in series between the MOSFET's drain pin and the microcontroller's digital input pin as shown in fig. 2.
simulate this circuit – Schematic created using CircuitLab
Figure 2.
If the addition of R2 does not reduce the amplitude of the preshoot voltage spikes to acceptable levels at the digital input pin, you can try adding a small value resistor in series with M1's gate, and adding a small capacitance (e.g., 2 nF) between M1's drain and ground. Note, however, that adding these components—and in particular, adding the capacitor—will slow down M1's switching times.