1

I have noticed something quite odd that I haven't seen before while using Git in PowerShell. I have a git repository that I am committing code to. Whenever I run git status to see the changed files, I see that the text in the console is offset by one character onto the previous line. I also did not re-size the window. Here is an example of what I am seeing: enter image description here

The word "modified" is offset back onto the previous line by one character.

I thought this was an issue in PowerShell, but after going through the properties of the window, I haven't been able to come up with anything that works and this only occurs when it is listing out the modified files (from what I can tell).

Why is Git offsetting the text like this in PowerShell and how can I fix it?

  • PowerShell Version: 5.1.18362.1171
  • Git Version: 2.29.2.windows.3

Update #1
As asked by @Bassie in the comments, I ran git config --list --show-origin [1] in order to list out the contents of the git configurations and I got the following results: git config

There does not seem to be any options within the config file that would do something like this.

I also noticed that if I put PowerShell into "Legacy Mode," then the formatting works as expected. This result lends credence to the idea that this may be a PowerShell issue rather than a Git issue. My question still stands above, if anyone has any ideas on how to fix this as this issue doesn't appear on another machine I have using PowerShell and Git.

Update #2
So, after running git config --list --show-origin, if I run git status again, then the formatting issue fixes itself. However, if I re-open up the PowerShell window and just run git status, then the formatting issue arises again. This may be an issue potentially with Git actually.

enter image description here

Code Doggo
  • 1,700
  • 4
  • 25
  • 51
  • 1
    Did you check in your git config, maybe there is some setting in there? – Bassie Dec 17 '20 at 04:25
  • @Bassie I just updated the question to provide my git configuration - definitely take a look at it let me know if you see anything of interest. Maybe I am missing something, but there doesn't appear to be anything within the config file that would cause this. I also noticed that if I put PowerShell into legacy mode, the formatting starts working correctly again. This feels like a PowerShell issue? I am not entirely sure. – Code Doggo Dec 17 '20 at 05:38
  • What version of git are you on? `git version` – Chad Baldwin Dec 17 '20 at 05:42
  • @ChadBaldwin I am running `2.29.2.windows.3`. I just put in another update on the question (i.e. "*Update #2*"). It looks like this may be a bug with git. – Code Doggo Dec 17 '20 at 05:46
  • Git is printing tab characters, and your window is interpreting "tab" as "move to rightmost column" instead of "move to next mod-8-equals-1 column". That is, the expected behavior of terminal emulators is that the tab-stops are columns 1, 9, 17, 25, ..., 73 (assuming 80-column emulator; add more tab-stops if the window is wider). – torek Dec 17 '20 at 07:45
  • It's likely that your pager, whatever it is set to, is sending escape sequences that fix the tab-stop positions in the window. There's probably some window setup configuration to set the tab stops. – torek Dec 17 '20 at 07:47
  • @torek I totally get what you are saying, but given that after running the git command `git config --list --show-origin` the issue fixes itself, makes me believe that this might be an issue with git itself right now. Are you running the same version with the same version of PowerShell? – Code Doggo Dec 20 '20 at 04:21
  • @torek There is no such pager configuration you are mentioning in the PowerShell window configuration. I've looked through all the possible options and I cannot find such a field you are referring to. – Code Doggo Dec 20 '20 at 04:24
  • 1
    Git itself runs a pager when running certain commands. The chosen pager is from `core.pager` or `$GIT_PAGER` or built in, or from command-line flags. `git status` does not use the pager (for some reason—it probably should, but historically it didn't, and so far, still doesn't) but other Git commands, including `git config --list`, do. – torek Dec 20 '20 at 07:02
  • @torek Ah thanks for the added context. I found that turning on the pager for the `git status` command solved the issue. I posted an answer for fixing this with credit to you. Thanks for pointing this out me. – Code Doggo Dec 20 '20 at 19:45

1 Answers1

0

@torek in the comments provided context to the issue at hand, which lead me to finding the solution:

"Git is printing tab characters, and your window is interpreting "tab" as "move to rightmost column" instead of "move to next mod-8-equals-1 column". [...] It's likely that your pager, whatever it is set to, is sending escape sequences that fix the tab-stop positions in the window. Git itself runs a pager when running certain commands. The chosen pager is from core.pager or $GIT_PAGER or built in, or from command-line flags. git status does not use the pager (for some reason—it probably should, but historically it didn't, and so far, still doesn't) but other Git commands, including git config --list, do."

After doing some further research into this, I found the following StackOverflow post, which provided a solution. The solution is to turn on the pager for the git status command by setting the Git configuration pager.status to true. This can be accomplished by running the following command:

git config --global pager.status true

Once this was done, even when run in a new PowerShell window, the git status command will now function as it should and the formatting issue will disappear: git status functions correctly

The problem has been solved! :)

Code Doggo
  • 1,700
  • 4
  • 25
  • 51