The command “Less” performs differently when invoked from Bash vs. from Git

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












When I view a large diff with git diff, it gets paged with less. This is confirmed by opening another window and checking data from ps -aux and /proc.



However, when less is invoked by Git, it does not revert the terminal content to its previous state after hitting q (the diff content remains in terminal), but when I run the command:



git diff commit1 commit2 --color | less -R


and quit less with the key q, the content disappears and the terminal reverts to the previous state.



More interestingly, when I export PAGER=less LESS='-R', and invoke git diff (or any other command that calls a pager), the command less behave the same as if invoked directly from Bash shell.



Below is a brief screenshot showing my problem. On the left pane, the commands are executed as follows:



unset PAGER GIT_PAGER LESS
git diff HEAD^ HEAD


On the right pane, I can see the commands. The latest commit was 100+ lines of y were written to a file. On both panes less can be exited with the key q.




i




Would you please explain what is different and why?










share|improve this question



























    up vote
    1
    down vote

    favorite












    When I view a large diff with git diff, it gets paged with less. This is confirmed by opening another window and checking data from ps -aux and /proc.



    However, when less is invoked by Git, it does not revert the terminal content to its previous state after hitting q (the diff content remains in terminal), but when I run the command:



    git diff commit1 commit2 --color | less -R


    and quit less with the key q, the content disappears and the terminal reverts to the previous state.



    More interestingly, when I export PAGER=less LESS='-R', and invoke git diff (or any other command that calls a pager), the command less behave the same as if invoked directly from Bash shell.



    Below is a brief screenshot showing my problem. On the left pane, the commands are executed as follows:



    unset PAGER GIT_PAGER LESS
    git diff HEAD^ HEAD


    On the right pane, I can see the commands. The latest commit was 100+ lines of y were written to a file. On both panes less can be exited with the key q.




    i




    Would you please explain what is different and why?










    share|improve this question

























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      When I view a large diff with git diff, it gets paged with less. This is confirmed by opening another window and checking data from ps -aux and /proc.



      However, when less is invoked by Git, it does not revert the terminal content to its previous state after hitting q (the diff content remains in terminal), but when I run the command:



      git diff commit1 commit2 --color | less -R


      and quit less with the key q, the content disappears and the terminal reverts to the previous state.



      More interestingly, when I export PAGER=less LESS='-R', and invoke git diff (or any other command that calls a pager), the command less behave the same as if invoked directly from Bash shell.



      Below is a brief screenshot showing my problem. On the left pane, the commands are executed as follows:



      unset PAGER GIT_PAGER LESS
      git diff HEAD^ HEAD


      On the right pane, I can see the commands. The latest commit was 100+ lines of y were written to a file. On both panes less can be exited with the key q.




      i




      Would you please explain what is different and why?










      share|improve this question















      When I view a large diff with git diff, it gets paged with less. This is confirmed by opening another window and checking data from ps -aux and /proc.



      However, when less is invoked by Git, it does not revert the terminal content to its previous state after hitting q (the diff content remains in terminal), but when I run the command:



      git diff commit1 commit2 --color | less -R


      and quit less with the key q, the content disappears and the terminal reverts to the previous state.



      More interestingly, when I export PAGER=less LESS='-R', and invoke git diff (or any other command that calls a pager), the command less behave the same as if invoked directly from Bash shell.



      Below is a brief screenshot showing my problem. On the left pane, the commands are executed as follows:



      unset PAGER GIT_PAGER LESS
      git diff HEAD^ HEAD


      On the right pane, I can see the commands. The latest commit was 100+ lines of y were written to a file. On both panes less can be exited with the key q.




      i




      Would you please explain what is different and why?







      git less






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 5 hours ago









      Goro

      2,29641849




      2,29641849










      asked 5 hours ago









      iBug

      688421




      688421




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          4
          down vote



          accepted










          Documentation:




          When the LESS environment variable is unset, Git sets it to FRX (if LESS environment variable is set, Git does not change it at all).




          The -X (--no-init) option is responsible for not clearing terminal after exit of less.






          share|improve this answer








          New contributor




          PetSerAl is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.

















          • Wow, great answer! I'd like to know if there's a git config to change this behavior (change the LESS environment that Git sets).
            – iBug
            2 hours ago










          • @iBug Looks like it is baked into the source. Thus you need to build your own Git to change that.
            – PetSerAl
            2 hours ago










          • I got Less 530 from FSF and compiled it myself. Now less -FR is very good to have. Thank you again!
            – iBug
            24 mins ago










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f469360%2fthe-command-less-performs-differently-when-invoked-from-bash-vs-from-git%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          4
          down vote



          accepted










          Documentation:




          When the LESS environment variable is unset, Git sets it to FRX (if LESS environment variable is set, Git does not change it at all).




          The -X (--no-init) option is responsible for not clearing terminal after exit of less.






          share|improve this answer








          New contributor




          PetSerAl is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.

















          • Wow, great answer! I'd like to know if there's a git config to change this behavior (change the LESS environment that Git sets).
            – iBug
            2 hours ago










          • @iBug Looks like it is baked into the source. Thus you need to build your own Git to change that.
            – PetSerAl
            2 hours ago










          • I got Less 530 from FSF and compiled it myself. Now less -FR is very good to have. Thank you again!
            – iBug
            24 mins ago














          up vote
          4
          down vote



          accepted










          Documentation:




          When the LESS environment variable is unset, Git sets it to FRX (if LESS environment variable is set, Git does not change it at all).




          The -X (--no-init) option is responsible for not clearing terminal after exit of less.






          share|improve this answer








          New contributor




          PetSerAl is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.

















          • Wow, great answer! I'd like to know if there's a git config to change this behavior (change the LESS environment that Git sets).
            – iBug
            2 hours ago










          • @iBug Looks like it is baked into the source. Thus you need to build your own Git to change that.
            – PetSerAl
            2 hours ago










          • I got Less 530 from FSF and compiled it myself. Now less -FR is very good to have. Thank you again!
            – iBug
            24 mins ago












          up vote
          4
          down vote



          accepted







          up vote
          4
          down vote



          accepted






          Documentation:




          When the LESS environment variable is unset, Git sets it to FRX (if LESS environment variable is set, Git does not change it at all).




          The -X (--no-init) option is responsible for not clearing terminal after exit of less.






          share|improve this answer








          New contributor




          PetSerAl is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          Documentation:




          When the LESS environment variable is unset, Git sets it to FRX (if LESS environment variable is set, Git does not change it at all).




          The -X (--no-init) option is responsible for not clearing terminal after exit of less.







          share|improve this answer








          New contributor




          PetSerAl is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          share|improve this answer



          share|improve this answer






          New contributor




          PetSerAl is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          answered 2 hours ago









          PetSerAl

          1562




          1562




          New contributor




          PetSerAl is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.





          New contributor





          PetSerAl is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.






          PetSerAl is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.











          • Wow, great answer! I'd like to know if there's a git config to change this behavior (change the LESS environment that Git sets).
            – iBug
            2 hours ago










          • @iBug Looks like it is baked into the source. Thus you need to build your own Git to change that.
            – PetSerAl
            2 hours ago










          • I got Less 530 from FSF and compiled it myself. Now less -FR is very good to have. Thank you again!
            – iBug
            24 mins ago
















          • Wow, great answer! I'd like to know if there's a git config to change this behavior (change the LESS environment that Git sets).
            – iBug
            2 hours ago










          • @iBug Looks like it is baked into the source. Thus you need to build your own Git to change that.
            – PetSerAl
            2 hours ago










          • I got Less 530 from FSF and compiled it myself. Now less -FR is very good to have. Thank you again!
            – iBug
            24 mins ago















          Wow, great answer! I'd like to know if there's a git config to change this behavior (change the LESS environment that Git sets).
          – iBug
          2 hours ago




          Wow, great answer! I'd like to know if there's a git config to change this behavior (change the LESS environment that Git sets).
          – iBug
          2 hours ago












          @iBug Looks like it is baked into the source. Thus you need to build your own Git to change that.
          – PetSerAl
          2 hours ago




          @iBug Looks like it is baked into the source. Thus you need to build your own Git to change that.
          – PetSerAl
          2 hours ago












          I got Less 530 from FSF and compiled it myself. Now less -FR is very good to have. Thank you again!
          – iBug
          24 mins ago




          I got Less 530 from FSF and compiled it myself. Now less -FR is very good to have. Thank you again!
          – iBug
          24 mins ago

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f469360%2fthe-command-less-performs-differently-when-invoked-from-bash-vs-from-git%23new-answer', 'question_page');

          );

          Post as a guest













































































          Comments

          Popular posts from this blog

          What does second last employer means? [closed]

          Installing NextGIS Connect into QGIS 3?

          One-line joke