I want to run the following commands:

git diff
git commit

git commit will open the default editor to edit the commit message. But if the difference if not too long it will close immediately.

How can I prevent closing git diff before pressing Enter or other keys?


git uses less as a pager. If you want to use the pager on a specific, just pipe the output directly to less (git won't try to invoke less itself if it is outputting to a pipe, so no need to worry about have two less processes). Just do:

git diff | less

You could also add similar options to less that git does to get the same output, and add the --color option to git diff to get colour:

git diff --color | less -RSX
  • None of them has code highlight. Anyway, is a valid solution. +1 – Ionică Bizău Mar 27 '14 at 20:30
  • @IonicăBizău, just add --color to git diff and -r or -R to less to get colour. – Graeme Mar 27 '14 at 20:34

You may be interested in the git commit --verbose command. This will show the output of git diff --staged in your editor as you enter the commit message.

  • I really like git commit --verbose. I am going to use it. +1 – Ionică Bizău Mar 27 '14 at 20:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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