There are several ways of copying text between programs on Linux. I'm just guessing that you're using Linux, but I don't think that this problem could occur on Windows or OSX. I also surmise that you're running Emacs as an X Windows application, not inside a terminal, else you wouldn't have this problem.
The first is by selecting text in program A and pasting it into program B. This is called the "primary selection", but the "secondary selection" is used so rarely that the name is becoming obsolete. When you select text, program A sends a message saying that the user has selected some text in one of its windows. All other programs hear this message and cancel any selections you might have made in their windows. When you paste, the current program sends a message to the program where the selection is asking it to send the text over to be pasted. By convention, you paste from the primary selection by clicking the middle mouse button.
The second is called the clipboard. When you copy some text in program A, it sends the text to the clipboard manager right away. Later, when you paste from the clipboard into program B, program B asks the clipboard manager for the text to be inserted. By convention, you paste from the clipboard with a keyboard shortcut or by selecting the action from a menu.
There's also a third method called cut buffers, but it's obsolete and you're probably not using it.
I surmise that you have selected some text in Emacs, and want to paste it into the editor launched by git commit
. That editor could be any program, but might be another instance of Emacs. Then you're running M-x shell-command git commit
, which synchronously executes git commit
. Then you try to paste into the new editor, but it fails. This is to be expected, because you selected text in Emacs, but then made Emacs synchronously execute some program. No program can respond to messages while taking any synchronous action, so of course the other editor might hang while waiting for the reply.
There are two ways to fix this. You already know that running git commit
asynchronously will fix it. You can also fix it by explicitly copying the text after selecting it. In the default configuration, Emacs sends whatever you copy to the clipboard as well as to the kill ring whenever you copy or kill text, so just hit M-w
(kill-ring-save
) before running git. Then, in the other editor, paste from the clipboard rather than the primary selection. Chapter 12.3 "Cut and Paste" Operationson Graphical Displays covers all the details if you want even more information.