Git Bash is displaying strange characters on Windows 7

后端 未结 3 1018
情深已故
情深已故 2021-02-14 04:44

I installed Gitbash in my Windows and defined the Linux command lines (ls to list directory for example) but the command line is returning strange characters.

Re         


        
相关标签:
3条回答
  • 2021-02-14 05:10

    You need to enable ansi control code processing. See here for details.

    By Jason Karns in shell

    • Link content included for reference in case link ever gets deleted.

    Having used git on windows for over three years now, I’ve fallen back in love with the command line. Bash, of course, not the windows command prompt. Beautiful, ubiquitous, warty bash. Git depends heavily on GNU utilities so on Windows it requires either cygwin or msys. Having been burned by cygwin in the past, I prefer the minimalism and simplicity of msys + mingw. Along with git, the entire ruby ecosystem lives in the shell. However, the numerous tools, gems and utilities that assume standard ANSI color support in the shell began to wear on me. Lo and behold, there is a lovely solution to provide ansi color support for bash (and cmd) on Windows: ansicon.

    Download the zip and extract. There are a few ways to install:

    1. Extract to a permanent location (I use C:/bin/ansicon). Execute ansicon.exe -i from within the appropriate directory for your system (x86/x64), and you’re all set. Any new shells (bash and windows cmd included) will autorun the ansicon utility for displaying color output. Be sure not to move the executable prior to running ansicon.exe –u. This removes the registry entry and prevents an ugly error message for every command shell.

    2. Alternatively, place the ansicon executable in your PATH, or add its location to your PATH. Then you can launch ansicon for a session with ansicon.exe –p.

    This utility has been working great for my on Windows XP. I’ve been having trouble getting it to work on Windows 7, but I hear it should be supported. I’ll post an update when the Windows 7 issue is resolved.

    Update

    Root cause, uncovered! If you use JRuby with a 64-bit JVM on Windows x64, ansicon won’t work. The issue is that ansicon (64-bit) is capable of injecting into 32-bit processes, but not vice versa. Currently, the JRuby launcher is a 32-bit executable. Thus, if you’re running a 64-bit shell (cmd, bash, or otherwise), ansicon will inject correctly into that process. It will then inject successfully into the 32-bit JRuby launcher process. At this point, for all intents and purposes, you’re running the 32-bit version of ansicon. Thus, if you’re running JRuby on a 64-bit JVM, then 32-bit ansicon is not able to inject into 64-bit JVM. There is an open feature request for JRuby to ship its 64-bit version with a 64-bit launcher. You should vote for this feature. I also hear that adoxa (Jason Hood) has a potential fix for this issue in the works. Stay posted.

    Of course, the easiest solution at the moment is to ensure that JRuby uses a 32-bit JVM. Just change (or set) your JAVA_HOME environment variable to point to a 32-bit JVM and you’re golden.

    Update 2: Issue Resolved

    The latest 64-bit binaries (ansi6432.zip) have fixed the issue. Just download and extract them over-top the 1.51 version.

    0 讨论(0)
  • 2021-02-14 05:14

    For MingGW64 I found going into the Options > Terminal and switching from xterm (the default I presume) to xterm-256color fixed the issue. I also restarted the console.

    0 讨论(0)
  • 2021-02-14 05:21

    I didn't remember the last version of GIT. I faced same problem after updating Git Bash to 2.11.

    Downgrading to 2.10 solved my problem. https://github.com/git-for-windows/git/releases/tag/v2.10.0.windows.1

    0 讨论(0)
提交回复
热议问题