【问题标题】:Git Bash is displaying strange characters on Windows 7 [closed]Git Bash 在 Windows 7 上显示奇怪的字符 [关闭]
【发布时间】:2016-02-14 02:19:41
【问题描述】:

我在我的 Windows 中安装了 Gitbash 并定义了 Linux 命令行(例如 ls to list directory),但是命令行返回了奇怪的字符。

Reginaldo@Dell MINGW64 /c/dev/php/laravel/flamboyant (master)
$ php artisan
←[32mLaravel Framework←[39m version ←[33m5.1.29 (LTS)←[39m

←[33mUsage:←[39m
  command [options] [arguments]

←[33mOptions:←[39m
  ←[32m-h, --help←[39m            Display this help message
  ←[32m-q, --quiet←[39m           Do not output any message
  ←[32m-V, --version←[39m         Display this application version
  ←[32m    --ansi←[39m            Force ANSI output
  ←[32m    --no-ansi←[39m         Disable ANSI output
  ←[32m-n, --no-interaction←[39m  Do not ask any interactive question
  ←[32m    --env[=ENV]←[39m       The environment the command should run under.
  ←[32m-v|vv|vvv, --verbose←[39m  Increase the verbosity of messages: 1 for norm
al output, 2 for more verbose output and 3 for debug

←[33mAvailable commands:←[39m
  ←[32mclear-compiled←[39m      Remove the compiled class file
  ←[32mdown←[39m                Put the application into maintenance mode
  ←[32menv←[39m                 Display the current framework environment
  ←[32mhelp←[39m                Displays help for a command
  ←[32minspire←[39m             Display an inspiring quote
  ←[32mlist←[39m                Lists commands
  ←[32mmigrate←[39m             Run the database migrations
  ←[32moptimize←[39m            Optimize the framework for better performance
  ←[32mserve←[39m               Serve the application on the PHP development ser
ver
  ←[32mtinker←[39m              Interact with your application
  ←[32mup←[39m                  Bring the application out of maintenance mode
 ←[33mapp←[39m
  ←[32mapp:name←[39m            Set the application namespace
 ←[33mauth←[39m
  ←[32mauth:clear-resets←[39m   Flush expired password reset tokens
 ←[33mcache←[39m
  ←[32mcache:clear←[39m         Flush the application cache
  ←[32mcache:table←[39m         Create a migration for the cache database table
 ←[33mconfig←[39m
  ←[32mconfig:cache←[39m        Create a cache file for faster configuration loa
ding
  ←[32mconfig:clear←[39m        Remove the configuration cache file
 ←[33mdb←[39m
  ←[32mdb:seed←[39m             Seed the database with records
 ←[33mevent←[39m
  ←[32mevent:generate←[39m      Generate the missing events and listeners based
on registration
 ←[33mhandler←[39m
  ←[32mhandler:command←[39m     Create a new command handler class
  ←[32mhandler:event←[39m       Create a new event handler class
 ←[33mkey←[39m
  ←[32mkey:generate←[39m        Set the application key
 ←[33mmake←[39m
  ←[32mmake:command←[39m        Create a new command class
  ←[32mmake:console←[39m        Create a new Artisan command
  ←[32mmake:controller←[39m     Create a new resource controller class
  ←[32mmake:event←[39m          Create a new event class
  ←[32mmake:job←[39m            Create a new job class
  ←[32mmake:listener←[39m       Create a new event listener class
  ←[32mmake:middleware←[39m     Create a new middleware class
  ←[32mmake:migration←[39m      Create a new migration file
  ←[32mmake:model←[39m          Create a new Eloquent model class
  ←[32mmake:policy←[39m         Create a new policy class
  ←[32mmake:provider←[39m       Create a new service provider class
  ←[32mmake:request←[39m        Create a new form request class
  ←[32mmake:seeder←[39m         Create a new seeder class
  ←[32mmake:test←[39m           Create a new test class
 ←[33mmigrate←[39m
  ←[32mmigrate:install←[39m     Create the migration repository
  ←[32mmigrate:refresh←[39m     Reset and re-run all migrations
  ←[32mmigrate:reset←[39m       Rollback all database migrations
  ←[32mmigrate:rollback←[39m    Rollback the last database migration
  ←[32mmigrate:status←[39m      Show the status of each migration
 ←[33mqueue←[39m
  ←[32mqueue:failed←[39m        List all of the failed queue jobs
  ←[32mqueue:failed-table←[39m  Create a migration for the failed queue jobs dat
abase table
  ←[32mqueue:flush←[39m         Flush all of the failed queue jobs
  ←[32mqueue:forget←[39m        Delete a failed queue job
  ←[32mqueue:listen←[39m        Listen to a given queue
  ←[32mqueue:restart←[39m       Restart queue worker daemons after their current
 job
  ←[32mqueue:retry←[39m         Retry a failed queue job
  ←[32mqueue:subscribe←[39m     Subscribe a URL to an Iron.io push queue
  ←[32mqueue:table←[39m         Create a migration for the queue jobs database t
able
  ←[32mqueue:work←[39m          Process the next job on a queue
 ←[33mroute←[39m
  ←[32mroute:cache←[39m         Create a route cache file for faster route regis
tration
  ←[32mroute:clear←[39m         Remove the route cache file
  ←[32mroute:list←[39m          List all registered routes
 ←[33mschedule←[39m
  ←[32mschedule:run←[39m        Run the scheduled commands
 ←[33msession←[39m
  ←[32msession:table←[39m       Create a migration for the session database tabl
e
 ←[33mtracker←[39m
  ←[32mtracker:tables←[39m      Create the migrations for Tracker database table
s and columns
 ←[33mvendor←[39m
  ←[32mvendor:publish←[39m      Publish any publishable assets from vendor packa
ges
 ←[33mview←[39m
  ←[32mview:clear←[39m          Clear all compiled view files

Reginaldo@Dell MINGW64 /c/dev/php/laravel/flamboyant (master)

有人可以帮帮我吗?

【问题讨论】:

  • 这些是终端控制代码。

标签: linux git bash


【解决方案1】:

您需要启用 ansi 控制代码处理。详情请见here

Jason Karns 在 shell 中

在 Windows 上使用 git 已经三年多了,我重新爱上了命令行。 Bash,当然不是 windows 命令提示符。美丽的,无处不在的,疣状的 bash。 Git 严重依赖 GNU 实用程序,因此在 Windows 上它需要 cygwin 或 msys。过去被cygwin烧过,我更喜欢msys + mingw的极简和简洁。与 git 一起,整个 ruby​​ 生态系统都存在于 shell 中。然而,在外壳中假定标准 ANSI 颜色支持的众多工具、宝石和实用程序开始让我感到厌烦。瞧,有一个可爱的解决方案可以为 Windows 上的 bash(和 cmd)提供 ansi 颜色支持:ansicon。

Download the zip and extract。有几种安装方式:

  1. 解压到一个永久位置(我使用C:/bin/ansicon)。在系统的相应目录 (x86/x64) 中执行 ansicon.exe -i,一切就绪。任何新的 shell(包括 bash 和 windows cmd)都将自动运行 ansicon 实用程序以显示颜色输出。确保在运行 ansicon.exe –u 之前不要移动可执行文件。这将删除注册表项并防止每个命令外壳出现丑陋的错误消息。

  2. 或者,将 ansicon 可执行文件放入您的 PATH,或将其位置添加到您的 PATH。然后您可以启动 ansicon 与ansicon.exe –p 进行会话。

这个实用程序在我的 Windows XP 上运行良好。我一直无法让它在 Windows 7 上运行,但我听说它应该得到支持。 Windows 7 问题解决后,我会发布更新。

更新

根本原因,uncovered!如果您在 Windows x64 上将 JRuby 与 64 位 JVM 一起使用,则 ansicon 将无法工作。问题是 ansicon(64 位)能够注入 32 位进程,但反之则不行。目前,JRuby 启动器是一个 32 位的可执行文件。因此,如果您正在运行 64 位 shell(cmd、bash 或其他),则 ansicon 将正确地注入该进程。然后它将成功注入 32 位 JRuby 启动器进程。此时,出于所有意图和目的,您正在运行 32 位版本的 ansicon。因此,如果您在 64 位 JVM 上运行 JRuby,则 32 位 ansicon 无法注入 64 位 JVM。有一个开放的功能请求 JRuby 发布带有 64 位启动器的 64 位版本。您应该投票支持此功能。我还听说 adoxa (Jason Hood) 有可能解决这个问题。保持发布。

当然,目前最简单的解决方案是确保 JRuby 使用 32 位 JVM。只需更改(或设置)您的 JAVA_HOME 环境变量以指向 32 位 JVM,您就可以了。

更新 2:问题已解决

最新的 64 位二进制文​​件 (ansi6432.z​​ip) 已解决此问题。只需在 1.51 版本之上下载并解压它们。

【讨论】:

  • 太棒了。这使得颜色在 CMD 中有效,但在 MingGW64 控制台中无效。
【解决方案2】:

对于 MingGW64,我发现进入选项 > 终端并从 xterm(我假设的默认值)切换到 xterm-256color 解决了这个问题。我还重新启动了控制台。

【讨论】:

  • @zhekaus 进行更改后您是否重新启动了终端?您是否尝试过这个问题的其他答案?您可以考虑查找与此类似的问题并检查这些解决方案。
  • 当然,我做到了!我已经在stackoverflow上尝试了一切,甚至更多!一切都是徒劳的!
  • @zhekaus 很遗憾听到您没有找到解决方案。您是否考虑过尝试使用不同的命令行工具。我推荐cmder.net
  • 这对我不起作用,但在框中写 cygwin 可以。
【解决方案3】:

This answer 帮助我处理了 Windows 中 git bash 的 gradle 输出中的怪异字符。只需将export TERM=cygwin 添加到git/etc/bash.bashrc 的最后一行即可。如果这对您有帮助,请务必为他们的答案点赞——我只是在这里转发它,因为这是谷歌带给我的地方。

【讨论】:

    【解决方案4】:

    我不记得 GIT 的最新版本。将 Git Bash 更新到 2.11 后,我遇到了同样的问题。

    降级到 2.10 解决了我的问题。 https://github.com/git-for-windows/git/releases/tag/v2.10.0.windows.1

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-10
      • 2011-06-28
      • 2014-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多