'Strange Powershell "interactive" behavior
Sometimes, when using certain commands within Powershell, the console is set into some kind of "interactive mode", which makes it behave in a way that's completely unusable for me, so I have to restart the console. I'm not sure whether it's a bug in Powershell or a feature I do not know about.
Here's a way to reproduce it (however, this is by far not the only way it happens):
- Navigate your Powershell console to a Git repository which is not too new, i.e. has at least a few dozen commits.
- Enter
git reflog
. - Git shows the list of the recent
HEAD
positions, which most of the time is a list of the last commits. - Press Ctrl+C or q to quit the list and return to the console.
- Optionally, press
cls
to clear the console screen.
Now, the console is in this weird mode. When I start typing, the console accepts some of the typed characters as usual, but some key presses seemingly let the console display fragments of the previous git reflog
command.
Here is an example: In a fresh powershell console, I did the steps described above. Then I entered abcdefghijklmn
. This is what this console is looking now:
As you can see, the characters j and l were treated like some commands that printed parts of the git reflog
output to the console window, but below the prompt.
Is that a bug or a feature? Anyone else having these problems?
Solution 1:[1]
Explanation
less
(default Git pager) does not interpret Ctrl+C as a quit command. You can open a new console window where less
will be the only application attached to it: start git reflog
to verify that.
When you press Ctrl+C and less
is not the only application attached to the current console window, then Ctrl+C gets received by the shell (PowerShell or CMD), and the shell asks the user for more input. You can see in task manager that after you press Ctrl+C, less
is still running, although the shell prints a new prompt for you. So now you have two applications which compete for single console window input buffer: some keys will be received by the first application, while other keys by the second application.
Solution
You need to type q and Enter multiple times to make sure less
will receive its q
.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | informatik01 |