2

I used 'M-x shell' to start a shell inside a buffer. Then I tried to run git diff

enter image description here

After I press the space bar a few time, the lines 29-69/69 line is printed a few and the shell has stopped responding.

Why it is the case? Is there anything to fix it?

EDIT

Did not see this error message when I used shell last time:

enter image description here

(I alias g to git)

Now I am not able to use git diff at all.

4
  • M-x shell or something else?
    – phils
    Jul 4, 2017 at 2:31
  • That's how I started the shell Jul 4, 2017 at 2:34
  • M-x shell is a dumb terminal, whereas it looks like the commands you're using are wanting a more full-functional terminal. In this case, it might just be wanting to invoke a pager. You could set your GIT_PAGER environment variable, or the core.pager git config option. Or else just use an actual terminal emulator instead of shell-mode. Emacs has one built in: M-x term (or ansi-term).
    – phils
    Jul 4, 2017 at 5:19
  • @phils I think M-x term is the answer. If you can post it as an answer to this question, i will accept it. Jul 4, 2017 at 5:24

1 Answer 1

5

M-x shell is a dumb terminal, whereas it looks like the commands you're using expect a more fully-featured terminal. This is what the "WARNING: terminal is not fully functional" messages are about.

To circumvent the general issue, you could use a proper terminal emulator instead of shell-mode. Emacs has one built in: M-x term (or M-x ansi-term).


Note that git might just be wanting to invoke a pager. So another approach would be to tell git not to use paged output, via the GIT_PAGER environment variable, or the core.pager git config option.

You could test this in the shell like so:

git --no-pager diff

or using the environment variable:

GIT_PAGER=cat git diff

or configure it permanently:

git config core.pager cat
git diff
3
  • I'll add that if using cat as the 'pager' for git like this, you may very well also wish to limit the number of lines of output for certain git commands, otherwise you may get a lot of output dumped into the buffer. e.g. git log provides an option to "Limit the number of commits to output." with can be specified with any of -<number>, -n <number>, --max-count=<number>
    – phils
    Feb 12, 2018 at 20:40
  • Or alternatively, you might use head (or a command which calls head with some custom max line-count argument) as your pager, instead of cat, and then use --no-pager in cases when you wish to disable that default limitation.
    – phils
    Feb 12, 2018 at 20:43
  • 1
    Personally I'd recommend using Magit, though (over any other approach to using git within Emacs).
    – phils
    Feb 12, 2018 at 20:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.