开门见山
git bash
windows
git
windows
cmd
然而,
git bash
cmd
mintty

git bash
mintty
mintty
cmd
git bash
cmd

举个简单的例子,如果想要查看当前目录的文件结构,最好是以目录树的形式展现,聪明的你获取已经猜到了
tree
git bash
tree
<pre class="brush:php;toolbar:false;">snowdreams1006@home MINGW64 /g/sublime/test$ treebash: tree: command not found
为了验证,确实没有
tree
git bash
tree.exe

经过验证,
git bash
tree.exe
tree
然而,
cmd
tree
cmd
tree
<pre class="brush:php;toolbar:false;">G:\sublime\test>tree卷 工作 的文件夹 PATH 列表卷序列号为 00000081 CC3C:50D0G:.├─cmd└─git

现在我们已经知道
git bash
linux
这些问题必须等我们弄清楚
mintty
mintty
mintty
mintty
putty
windows

mintty
git bash
<pre class="brush:php;toolbar:false;">$ mintty --helpUsage: mintty [OPTION]... [ PROGRAM [ARG]... | - ]Start a new terminal session running the specified program or the user's shell.If a dash is given instead of a program, invoke the shell as a login shell.Options: -c, --config FILE Load specified config file -e, --exec Treat remaining arguments as the command to execute -h, --hold never|start|error|always Keep window open after command finishes -i, --icon FILE[,IX] Load window icon from file, optionally with index -l, --log FILE|- Log output to file or stdout -o, --option OPT=VAL Override config file option with given value -p, --position X,Y Open window at specified coordinates -s, --size COLS,ROWS Set screen size in characters -t, --title TITLE Set window title (default: the invoked command) -u, --utmp Create a utmp entry -w, --window normal|min|max|full|hide Set initial window state --class CLASS Set window class name (default: mintty) -H, --help Display help and exit -V, --version Print version information and exit
如果想要自定义
mintty
git bash

mingw

msys

cygwin

gnu

git bash
mintty
mintty
mingw
msys2
cygwin
gnu
gnu
正因如此,江山代有才人出,前人栽树后人乘凉,
cygwin
gnu
windows
linux
或许由于这套方案太完整,功能齐全因而软件包体积庞大,因此
mingw
msys
开源的力量是可持续的,慢慢的,这些操作系统的内置终端功能也被单独提取出来,
mintty
说到开源,自然是少不了
git
git
Unix
windows
Git For Windows
git
windows
gnu
Git Bash Here
Git For Windows
mintty

弄清楚事情的来龙去脉后,对我们解决问题有什么帮助呢?
帮助可大了去了,刨根问题找到了源头,问题自然迎刃而解!
我劝少年放弃吧你确定不是在逗我?让我直接放弃?

亲,真的抱歉呢,放弃是解决问题的最快途径!
...
谈一谈为什么要放弃?
git bash
mintty
mintty
cmd
所以默认情况下,如果没有提供某些命令,那我们只好放弃在
git bash
此路不通,自然会寻求其他解决途径,比如可以借助
cmd
git bash
既然本文是
tree
tree
git bash
cmd
值得注意的是,
cmd
tree
.exe
.com
所以
git bash
tree
/usr/bin
tree.exe
tree.exe
那么第一种调用方法便是补全后缀名,这样自然能够调用
cmd
tree.com

我擦,竟然出现乱码,根据我多年的开发经验来看,乱码问题多半是编码问题导致的,那么修改下终端的编码设置应该就能解决问题.


瞬间被打脸,无论是原来的
git bash
然而,我是不会承认被打脸的,世人皆醉我独醒,肯定是
bug
cmd
既然
git bash
tree
cmd
tree
在
cmd
tree
git bash
cmd
tree
<pre class="brush:php;toolbar:false;"># 直接输入 `tree` 命令,正确响应并且无中文乱码.G:\sublime\test>tree卷 工作 的文件夹 PATH 列表卷序列号为 00000093 CC3C:50D0G:.├─cmd└─git# 输入 `cmd tree` 命令,虽无报错,但也没有正确响应.G:\sublime\test>cmd treeMicrosoft Windows [版本 6.3.9600](c) 2013 Microsoft Corporation。保留所有权利。
因此,我们需要告诉
git bash
cmd
tree
<pre class="brush:php;toolbar:false;"># 注意看前缀是 `snowdreams1006@home MINGW64` 表明当前处于 `git bash` 环境snowdreams1006@home MINGW64 /g/sublime/test# 输入 `cmd tree` 命令,虽无报错,但也没有正确响应,并且仍然有中文乱码.$ cmd treeMicrosoft Windows [▒汾 6.3.9600](c) 2013 Microsoft Corporation▒▒▒▒▒▒▒▒▒▒Ȩ▒▒▒▒# 输出 `tree` 命令,正确响应但有中文乱码.此时命令行前缀已经更改为 `G:\sublime\test>` 表明当前不再处于`git bash` 环境!G:\sublime\test>treetree▒▒ ▒▒▒▒ ▒▒▒ļ▒▒▒ PATH ▒б▒▒▒▒▒▒к▒Ϊ 0000006B CC3C:50D0G:.▒▒▒▒cmd▒▒▒▒git
通过上述操作结果来看,不难发现以下问题.
cmd tree
cmd
tree
cmd tree
cmd dir
cmd
bash
cmd
tree
cmd
Ctrl + C
git bash
由此可见,不加任何参数冒昧进入到
cmd
cmd //c tree
<pre class="brush:php;toolbar:false;">snowdreams1006@home MINGW64 /g/sublime/test$ cmd //c tree▒▒ ▒▒▒▒ ▒▒▒ļ▒▒▒ PATH ▒б▒▒▒▒▒▒к▒Ϊ 00000008 CC3C:50D0G:.▒▒▒▒cmd▒▒▒▒gitsnowdreams1006@home MINGW64 /g/sublime/test$
cmd
简单总结下,如何在
git bash
cmd
tree
tree.com
cmd //c tree
cmd
tree
tree
调用
tree
解决问题最快速的方式是百度一下或者从官网寻求帮助,这次我选择后者,因为百度一下人人都会,不用我再讲了吧!

简单解释下这段话的意思:
如果在
mintty
cmd
winpty
cmd

有什么神奇之处?不妨加上
winpty
<pre class="brush:php;toolbar:false;">snowdreams1006@home MINGW64 /g/sublime/test# `winpty` + `tree.com` : 正常输出且无中文乱码 $ winpty tree.com卷 工作 的文件夹 PATH 列表卷序列号为 00000074 CC3C:50D0G:.├─cmd└─gitsnowdreams1006@home MINGW64 /g/sublime/test# `winpty` + `cmd //c tree` : 正常输出且无中文乱码$ winpty cmd //c tree卷 工作 的文件夹 PATH 列表卷序列号为 000000B3 CC3C:50D0G:.├─cmd└─gitsnowdreams1006@home MINGW64 /g/sublime/test$
果然是神药,一下子就治好了我多年的老寒腿啊!
winpty tree.com
winpty cmd //c tree
既然已经提供了解决方案,那文章是不是应该到此为止了呢?
不不不,远远还没结束,这只是开胃小菜,好戏还在后头呢.
更何况这命令也忒长了,记不住啊!
很简单,可以设置别名啊,把常用命令设置成别名,这样就记住啦!
输入
alias
<pre class="brush:php;toolbar:false;">snowdreams1006@home MINGW64 /g/sublime/test$ aliasalias ll='ls -l'alias ls='ls -F --color=auto --show-control-chars'alias node='winpty node.exe'
按照
linux
<pre class="brush:php;toolbar:false;">snowdreams1006@home MINGW64 /g/sublime/test$ cat /etc/bashrccat: /etc/bashrc: No such file or directorysnowdreams1006@home MINGW64 /g/sublime/test$ cat ~/.bashrccat: /c/Users/snowdreams1006/.bashrc: No such file or directory
竟然配置文件都不存在?

当然不存在了啊!快醒醒,你是在
windows
linux
脑海中迅速闪现哲学基本问题: 我是谁,我在那,我在干什么?
我是
windows
git bash
linux
既然你明白你何出来,那你去那里看看有没有什么发现?
代码语言:javascript代码运行次数:0运行复制<pre class="brush:php;toolbar:false;">snowdreams1006@home MINGW64 /g/sublime/test$ cd /e/gitsnowdreams1006@home MINGW64 /e/git$ winpty tree.com卷 软件 的文件夹 PATH 列表卷序列号为 00000063 223E:7300E:.├─bin├─cmd├─dev│ ├─mqueue│ └─shm├─etc│ ├─pkcs11│ ├─pki│ │ └─ca-trust│ │ ├─extracted│ │ │ ├─java│ │ │ ├─openssl│ │ │ └─pem│ │ └─source│ │ └─anchors│ ├─profile.d│ └─ssh├─mingw64│ ├─bin│ ├─doc│ │ └─git-credential-manager│ ├─etc│ │ ├─pkcs11│ │ └─pki│ │ └─ca-trust│ │ └─extracted│ │ ├─java│ │ ├─openssl│ │ └─pem│ ├─lib│ │ ├─dde1.4│ │ ├─engines│ │ ├─itcl4.0.4│ │ ├─p11-kit│ │ ├─pkcs11│ │ ├─reg1.3│ │ ├─sqlite3.11.0│ │ ├─tcl8│ │ │ ├─8.4│ │ │ │ └─platform│ │ │ ├─8.5│ │ │ └─8.6│ │ │ └─tdbc│ │ ├─tcl8.6│ │ │ ├─encoding│ │ │ ├─http1.0│ │ │ ├─msgs│ │ │ ├─opt0.4│ │ │ └─tzdata│ │ │ ├─Africa│ │ │ ├─America│ │ │ │ ├─Argentina│ │ │ │ ├─Indiana│ │ │ │ ├─Kentucky│ │ │ │ └─North_Dakota│ │ │ ├─Antarctica│ │ │ ├─Arctic│ │ │ ├─Asia│ │ │ ├─Atlantic│ │ │ ├─Australia│ │ │ ├─Brazil│ │ │ ├─Canada│ │ │ ├─Chile│ │ │ ├─Etc│ │ │ ├─Europe│ │ │ ├─Indian│ │ │ ├─Mexico│ │ │ ├─Pacific│ │ │ ├─SystemV│ │ │ └─US│ │ ├─thread2.7.3│ │ └─tk8.6│ │ ├─demos│ │ │ └─images│ │ ├─images│ │ ├─msgs│ │ └─ttk│ ├─libexec│ │ └─git-core│ │ └─mergetools│ ├─share│ │ ├─antiword│ │ ├─doc│ │ │ ├─connect│ │ │ ├─git-doc│ │ │ │ ├─howto│ │ │ │ └─technical│ │ │ └─nghttp2│ │ ├─gettext-0.19.7│ │ │ └─its│ │ ├─git│ │ │ ├─bindimage.txt│ │ │ └─completion│ │ ├─git-core│ │ │ └─templates│ │ │ ├─hooks│ │ │ └─info│ │ ├─git-gui│ │ │ └─lib│ │ ├─gitweb│ │ │ └─static│ │ ├─licenses│ │ │ ├─bzip2│ │ │ ├─expat│ │ │ ├─gcc-libs│ │ │ ├─gettext│ │ │ │ ├─gettext-runtime│ │ │ │ │ ├─intl│ │ │ │ │ └─libasprintf│ │ │ │ ├─gettext-tools│ │ │ │ │ └─gnulib-lib│ │ │ │ │ └─libxml│ │ │ │ └─gnulib-local│ │ │ │ └─lib│ │ │ │ └─libxml│ │ │ ├─libffi│ │ │ ├─libiconv│ │ │ │ └─libcharset│ │ │ ├─libssh2│ │ │ ├─libsystre│ │ │ ├─libtasn1│ │ │ ├─libtre│ │ │ ├─libwinpthread│ │ │ │ └─mingw-w64-libraries│ │ │ │ └─winpthreads│ │ │ ├─openssl│ │ │ ├─wineditline│ │ │ └─zlib│ │ ├─nghttp2│ │ ├─p11-kit│ │ │ └─modules│ │ ├─perl5│ │ │ └─site_perl│ │ │ └─Git│ │ │ └─SVN│ │ │ └─Memoize│ │ └─pki│ │ └─ca-trust-source│ └─ssl│ └─certs├─tmp└─usr ├─bin │ ├─core_perl │ └─vendor_perl ├─lib │ ├─awk │ ├─coreutils │ ├─gawk │ ├─gnupg │ │ └─gnupg │ ├─openssl │ │ └─engines │ ├─p11-kit │ ├─perl5 │ │ ├─core_perl │ │ │ ├─auto │ │ │ │ ├─arybase │ │ │ │ ├─attributes │ │ │ │ ├─B │ │ │ │ ├─Compress │ │ │ │ │ └─Raw │ │ │ │ │ ├─Bzip2 │ │ │ │ │ └─Zlib │ │ │ │ ├─Cwd │ │ │ │ ├─Data │ │ │ │ │ └─Dumper │ │ │ │ ├─DB_File │ │ │ │ ├─Devel │ │ │ │ │ ├─Peek │ │ │ │ │ └─PPPort │ │ │ │ ├─Digest │ │ │ │ │ ├─MD5 │ │ │ │ │ └─SHA │ │ │ │ ├─Encode │ │ │ │ │ ├─Byte │ │ │ │ │ ├─CN │ │ │ │ │ ├─EBCDIC │ │ │ │ │ ├─JP │ │ │ │ │ ├─KR │ │ │ │ │ ├─Symbol │ │ │ │ │ ├─TW │ │ │ │ │ └─Unicode │ │ │ │ ├─Fcntl │ │ │ │ ├─File │ │ │ │ │ ├─DosGlob │ │ │ │ │ └─Glob │ │ │ │ ├─Filter │ │ │ │ │ └─Util │ │ │ │ │ └─Call │ │ │ │ ├─GDBM_File │ │ │ │ ├─Hash │ │ │ │ │ └─Util │ │ │ │ │ └─FieldHash │ │ │ │ ├─I18N │ │ │ │ │ └─Langinfo │ │ │ │ ├─IO │ │ │ │ ├─IPC │ │ │ │ │ └─SysV │ │ │ │ ├─List │ │ │ │ │ └─Util │ │ │ │ ├─Math │ │ │ │ │ └─BigInt │ │ │ │ │ └─FastCalc │ │ │ │ ├─MIME │ │ │ │ │ └─Base64 │ │ │ │ ├─mro │ │ │ │ ├─NDBM_File │ │ │ │ ├─ODBM_File │ │ │ │ ├─Opcode │ │ │ │ ├─PerlIO │ │ │ │ │ ├─encoding │ │ │ │ │ ├─mmap │ │ │ │ │ ├─scalar │ │ │ │ │ └─via │ │ │ │ ├─POSIX │ │ │ │ ├─re │ │ │ │ ├─SDBM_File │ │ │ │ ├─Socket │ │ │ │ ├─Storable │ │ │ │ ├─Sys │ │ │ │ │ ├─Hostname │ │ │ │ │ └─Syslog │ │ │ │ ├─threads │ │ │ │ │ └─shared │ │ │ │ ├─Tie │ │ │ │ │ └─Hash │ │ │ │ │ └─NamedCapture │ │ │ │ ├─Time │ │ │ │ │ ├─HiRes │ │ │ │ │ └─Piece │ │ │ │ ├─Unicode │ │ │ │ │ └─Collate │ │ │ │ ├─Win32 │ │ │ │ ├─Win32API │ │ │ │ │ └─File │ │ │ │ └─Win32CORE │ │ │ ├─B │ │ │ ├─Compress │ │ │ │ └─Raw │ │ │ ├─CORE │ │ │ ├─Data │ │ │ ├─Devel │ │ │ ├─Digest │ │ │ ├─Encode │ │ │ │ ├─CN │ │ │ │ ├─JP │ │ │ │ ├─KR │ │ │ │ ├─MIME │ │ │ │ │ └─Header │ │ │ │ └─Unicode │ │ │ ├─File │ │ │ │ └─Spec │ │ │ ├─Filter │ │ │ │ └─Util │ │ │ ├─Hash │ │ │ │ └─Util │ │ │ ├─I18N │ │ │ ├─IO │ │ │ │ └─Socket │ │ │ ├─IPC │ │ │ ├─List │ │ │ │ └─Util │ │ │ ├─Math │ │ │ │ └─BigInt │ │ │ ├─MIME │ │ │ ├─PerlIO │ │ │ ├─Scalar │ │ │ ├─Sub │ │ │ ├─Sys │ │ │ ├─threads │ │ │ ├─Tie │ │ │ │ └─Hash │ │ │ ├─Time │ │ │ ├─Unicode │ │ │ │ └─Collate │ │ │ └─Win32API │ │ └─vendor_perl │ │ ├─auto │ │ │ ├─HTML │ │ │ │ └─Parser │ │ │ ├─Net │ │ │ │ └─SSLeay │ │ │ ├─SVN │ │ │ │ ├─_Client │ │ │ │ ├─_Core │ │ │ │ ├─_Delta │ │ │ │ ├─_Fs │ │ │ │ ├─_Ra │ │ │ │ ├─_Repos │ │ │ │ └─_Wc │ │ │ └─Term │ │ │ └─ReadKey │ │ ├─HTML │ │ ├─Net │ │ │ └─SSLeay │ │ ├─SVN │ │ └─Term │ ├─pkcs11 │ ├─sasl2 │ ├─ssh │ ├─tar │ └─terminfo │ ├─63 │ ├─64 │ └─78 ├─libexec ├─share │ ├─bash-completion │ │ └─completions │ ├─cygwin │ ├─git │ ├─gnupg │ ├─licenses │ │ ├─curl │ │ ├─dos2unix │ │ ├─expat │ │ ├─file │ │ ├─gcc-libs │ │ ├─libffi │ │ ├─libsasl │ │ ├─libsqlite │ │ ├─libssh2 │ │ ├─mintty │ │ ├─ncurses │ │ ├─openssh │ │ ├─openssl │ │ ├─p11-kit │ │ ├─perl-Net-SSLeay │ │ ├─perl-TermReadKey │ │ ├─unzip │ │ ├─vim │ │ └─zlib │ ├─misc │ ├─p11-kit │ │ └─modules │ ├─perl5 │ │ ├─core_perl │ │ │ ├─App │ │ │ │ └─Prove │ │ │ │ └─State │ │ │ │ └─Result │ │ │ ├─Archive │ │ │ │ └─Tar │ │ │ ├─Attribute │ │ │ ├─autodie │ │ │ │ ├─exception │ │ │ │ └─Scope │ │ │ ├─B │ │ │ ├─Carp │ │ │ ├─Class │ │ │ ├─Compress │ │ │ ├─Config │ │ │ │ └─Perl │ │ │ ├─CPAN │ │ │ │ ├─Exception │ │ │ │ ├─FTP │ │ │ │ ├─HTTP │ │ │ │ ├─Kwalify │ │ │ │ ├─LWP │ │ │ │ ├─Meta │ │ │ │ └─Plugin │ │ │ ├─DBM_Filter │ │ │ ├─Devel │ │ │ ├─Digest │ │ │ ├─Encode │ │ │ ├─encoding │ │ │ ├─Exporter │ │ │ ├─ExtUtils │ │ │ │ ├─CBuilder │ │ │ │ │ └─Platform │ │ │ │ │ └─Windows │ │ │ │ ├─Command │ │ │ │ ├─Constant │ │ │ │ ├─Liblist │ │ │ │ ├─MakeMaker │ │ │ │ │ └─version │ │ │ │ ├─ParseXS │ │ │ │ └─Typemaps │ │ │ ├─File │ │ │ ├─Filter │ │ │ ├─Getopt │ │ │ ├─HTTP │ │ │ ├─I18N │ │ │ │ └─LangTags │ │ │ ├─IO │ │ │ │ ├─Compress │ │ │ │ │ ├─Adapter │ │ │ │ │ ├─Base │ │ │ │ │ ├─Gzip │ │ │ │ │ ├─Zip │ │ │ │ │ └─Zlib │ │ │ │ ├─Socket │ │ │ │ └─Uncompress │ │ │ │ └─Adapter │ │ │ ├─IPC │ │ │ ├─JSON │ │ │ │ └─PP │ │ │ ├─Locale │ │ │ │ ├─Codes │ │ │ │ └─Maketext │ │ │ ├─Math │ │ │ │ ├─BigFloat │ │ │ │ └─BigInt │ │ │ ├─Memoize │ │ │ ├─Module │ │ │ │ ├─CoreList │ │ │ │ └─Load │ │ │ ├─Net │ │ │ │ └─FTP │ │ │ ├─overload │ │ │ ├─Params │ │ │ ├─Parse │ │ │ │ └─CPAN │ │ │ ├─Perl │ │ │ ├─PerlIO │ │ │ │ └─via │ │ │ ├─Pod │ │ │ │ ├─Perldoc │ │ │ │ ├─Simple │ │ │ │ └─Text │ │ │ ├─Search │ │ │ ├─TAP │ │ │ │ ├─Formatter │ │ │ │ │ ├─Console │ │ │ │ │ └─File │ │ │ │ ├─Harness │ │ │ │ └─Parser │ │ │ │ ├─Iterator │ │ │ │ ├─Result │ │ │ │ ├─Scheduler │ │ │ │ ├─SourceHandler │ │ │ │ └─YAMLish │ │ │ ├─Term │ │ │ ├─Test │ │ │ │ ├─Builder │ │ │ │ │ ├─IO │ │ │ │ │ └─Tester │ │ │ │ ├─Tester │ │ │ │ └─use │ │ │ ├─Text │ │ │ ├─Thread │ │ │ ├─Tie │ │ │ ├─Time │ │ │ ├─Unicode │ │ │ │ └─Collate │ │ │ │ └─CJK │ │ │ ├─unicore │ │ │ │ ├─lib │ │ │ │ │ ├─Age │ │ │ │ │ ├─Alpha │ │ │ │ │ ├─Bc │ │ │ │ │ ├─BidiC │ │ │ │ │ ├─BidiM │ │ │ │ │ ├─Blk │ │ │ │ │ ├─Bpt │ │ │ │ │ ├─Cased │ │ │ │ │ ├─Ccc │ │ │ │ │ ├─CE │ │ │ │ │ ├─CI │ │ │ │ │ ├─CompEx │ │ │ │ │ ├─CWCF │ │ │ │ │ ├─CWCM │ │ │ │ │ ├─CWKCF │ │ │ │ │ ├─CWL │ │ │ │ │ ├─CWT │ │ │ │ │ ├─CWU │ │ │ │ │ ├─Dash │ │ │ │ │ ├─Dep │ │ │ │ │ ├─DI │ │ │ │ │ ├─Dia │ │ │ │ │ ├─Dt │ │ │ │ │ ├─Ea │ │ │ │ │ ├─Ext │ │ │ │ │ ├─Gc │ │ │ │ │ ├─GCB │ │ │ │ │ ├─GrBase │ │ │ │ │ ├─Hex │ │ │ │ │ ├─Hst │ │ │ │ │ ├─Hyphen │ │ │ │ │ ├─IDC │ │ │ │ │ ├─Ideo │ │ │ │ │ ├─IDS │ │ │ │ │ ├─In │ │ │ │ │ ├─Jg │ │ │ │ │ ├─Jt │ │ │ │ │ ├─Lb │ │ │ │ │ ├─LOE │ │ │ │ │ ├─Lower │ │ │ │ │ ├─Math │ │ │ │ │ ├─NChar │ │ │ │ │ ├─NFCQC │ │ │ │ │ ├─NFDQC │ │ │ │ │ ├─NFKCQC │ │ │ │ │ ├─NFKDQC │ │ │ │ │ ├─Nt │ │ │ │ │ ├─Nv │ │ │ │ │ ├─PatSyn │ │ │ │ │ ├─PatWS │ │ │ │ │ ├─Perl │ │ │ │ │ ├─QMark │ │ │ │ │ ├─SB │ │ │ │ │ ├─Sc │ │ │ │ │ ├─Scx │ │ │ │ │ ├─SD │ │ │ │ │ ├─STerm │ │ │ │ │ ├─Term │ │ │ │ │ ├─UIdeo │ │ │ │ │ ├─Upper │ │ │ │ │ ├─WB │ │ │ │ │ ├─XIDC │ │ │ │ │ └─XIDS │ │ │ │ └─To │ │ │ ├─User │ │ │ ├─version │ │ │ ├─warnings │ │ │ └─Win32API │ │ │ └─File │ │ └─vendor_perl │ │ ├─Authen │ │ │ └─SASL │ │ │ └─Perl │ │ ├─Convert │ │ ├─Date │ │ │ └─Language │ │ ├─Encode │ │ ├─Error │ │ ├─File │ │ ├─HTML │ │ ├─HTTP │ │ │ ├─Cookies │ │ │ ├─Headers │ │ │ └─Request │ │ ├─IO │ │ │ └─Socket │ │ │ └─SSL │ │ ├─LWP │ │ │ ├─Authen │ │ │ └─Protocol │ │ ├─Mail │ │ │ ├─Field │ │ │ └─Mailer │ │ ├─MIME │ │ │ ├─Decoder │ │ │ ├─Field │ │ │ └─Parser │ │ ├─Net │ │ │ ├─HTTP │ │ │ └─SMTP │ │ ├─Time │ │ ├─URI │ │ │ ├─file │ │ │ └─urn │ │ └─WWW │ │ └─RobotRules │ ├─pki │ │ └─ca-trust-source │ ├─tabset │ ├─terminfo │ │ ├─63 │ │ ├─64 │ │ └─78 │ └─vim │ └─vim74 │ ├─autoload │ │ └─xml │ ├─colors │ ├─compiler │ ├─doc │ ├─ftplugin │ ├─indent │ ├─keymap │ ├─macros │ │ ├─hanoi │ │ ├─life │ │ ├─maze │ │ └─urm │ ├─pack │ │ └─dist │ │ └─opt │ │ ├─dvorak │ │ │ ├─dvorak │ │ │ └─plugin │ │ ├─editexisting │ │ │ └─plugin │ │ ├─justify │ │ │ └─plugin │ │ ├─matchit │ │ │ ├─doc │ │ │ └─plugin │ │ ├─shellmenu │ │ │ └─plugin │ │ └─swapmouse │ │ └─plugin │ ├─plugin │ ├─print │ ├─spell │ ├─syntax │ ├─tools │ └─tutor └─ssl ├─certs └─misc
看到熟悉的
./etc/bash.bashrc
<pre class="brush:php;toolbar:false;">snowdreams1006@home MINGW64 /e/git$ echo "# Set alias for tree command" >> ./etc/bash.bashrcsnowdreams1006@home MINGW64 /e/git$ echo "alias tree='winpty tree.com'" >> ./etc/bash.bashrcsnowdreams1006@home MINGW64 /e/git$ source ./etc/bash.bashrc
现在测试一下能否正确打印出目录树:
代码语言:javascript代码运行次数:0运行复制<pre class="brush:php;toolbar:false;">snowdreams1006@home MINGW64 /e/git$ cd /g/sublime/testsnowdreams1006@home MINGW64 /g/sublime/test$ tree卷 工作 的文件夹 PATH 列表卷序列号为 000000A3 CC3C:50D0G:.├─cmd└─git
亲测有效,通过设置别名的方式可以简化命令,从而实现在
git bash
tree
git bash
tree
mintty
tree
mintty
tree
cygwin
msys2
mingw
回想起
linux
tree
tree
因此,思路有两种,像
linux
tree
tree
第一种需要包管理工具,而
git bash
mintty
tree
如果能够提供包管理工具,那么我们就可以像
linux
tree
首先想到的是
mintty
mintty

<pre class="brush:php;toolbar:false;">Administrator@snowdreams1006 MINGW64 /f/workspace/test$ mingw-getbash: mingw-get: command not foundAdministrator@snowdreams1006 MINGW64 /f/workspace/test$ pacmanbash: pacman: command not found
然而,小小的挫折是不会轻易放弃的,既然
mintty
git
git

频繁出现
Git For Windows
Git For Windows
git bash
mintty
所以,我们有理由相信
Git For Windows
git


根据官方说明,安装后正在下载相关依赖,下载速度比较慢的话,请自行解决.

下载完成后,原来的
cmd
git bash

<pre class="brush:php;toolbar:false;">Administrator@snowdreams1006 MINGW64 / (master)$ sdk helpThe 'sdk' shell function helps you to get up and runningwith the Git for Windows SDK. The available subcommands are:create-desktop-icon: install a desktop icon that starts the Git for Windows SDK Bash.cd <project>: initialize/update a worktree and cd into it. Known projects: git git-extra msys2-runtime installer build-extra MINGW-packages MSYS2-packages mingw-w64-busybox mingw-w64-curl mingw-w64-cv2pdb mingw-w64-git mingw-w64-git-credential-manager mingw-w64-git-lfs mingw-w64-git-sizer mingw-w64-wintoast bash curl gawk git-flow gnupg heimdal mintty nodejs openssh openssl perl perl-HTML-Parser perl-Locale-Gettext perl-Net-SSLeay perl-TermReadKey perl-XML-Parser perl-YAML-Syck subversion tiginit <project>: initialize and/or update a worktree. Known projects are the same as for the 'cd' command.build <project>: builds one of the following: git-and-installer git git-extra msys2-runtime installer mingw-w64-busybox mingw-w64-curl mingw-w64-cv2pdb mingw-w64-git mingw-w64-git-credential-manager mingw-w64-git-lfs mingw-w64-git-sizer mingw-w64-wintoast bash curl gawk git-flow gnupg heimdal mintty nodejs openssh openssl perl perl-HTML-Parser perl-Locale-Gettext perl-Net-SSLeay perl-TermReadKey perl-XML-Parser perl-YAML-Syck subversion tigedit <file>: edit a well-known file. Well-known files are: git-sdk.sh sdk.completion ReleaseNotes.md install.issreload: reload the 'sdk' function.
现在安装完成后,我们再次打开
Git For Windows
msys2

根据科普知识,我们知道
msys2
mingw
Git For Windows
msys2
<pre class="brush:php;toolbar:false;">Administrator@snowdreams1006 MINGW64 / (master)$ Pacman -h用法:  Pacman <操作> [...]操作:    Pacman {-h --help}    Pacman {-V --version}    Pacman {-D --database} <选项> <软件包>    Pacman {-F --files}    [选项] [软件包]    Pacman {-Q --query}    [选项] [软件包]    Pacman {-R --remove}   [选项] <软件包>    Pacman {-S --sync}     [选项] [软件包]    Pacman {-T --deptest}  [选项] [软件包]    Pacman {-U --upgrade}  [选项] <文件>使用 'Pacman {-h --help}' 及某个操作以查看可用选项激动人心的时刻就要来临,在正式使用
Pacman
tree
git bash
tree
<pre class="brush:php;toolbar:false;">Administrator@snowdreams1006 MINGW64 / (master)$ treebash: tree: 未找到命令
调用
Pacman -S tree
tree
<pre class="brush:php;toolbar:false;">Administrator@snowdreams1006 MINGW64 / (master)$ Pacman -S tree正在解析依赖关系...正在查找软件包冲突...软件包 (1) tree-1.8.0-1下载大小: 0.05 MiB全部安装大小: 0.07 MiB:: 进行安装吗? [Y/n] y警告:没有 /var/cache/pacman/pkg/ 缓存存在,正在创建...:: 正在获取软件包...... tree-1.8.0-1-x86_64 51.1 KiB 211K/s 00:00 [#####################] 100%(1/1) 正在检查密钥环里的密钥 [#####################] 100%(1/1) 正在检查软件包完整性 [#####################] 100%(1/1) 正在加载软件包文件 [#####################] 100%(1/1) 正在检查文件冲突 [#####################] 100%(1/1) 正在检查可用存储空间 [#####################] 100%:: 正在处理软件包的变化...(1/1) 正在安装 tree
验证安装成功,切换到测试目录调用
tree
<pre class="brush:php;toolbar:false;">Administrator@snowdreams1006 MINGW64 / (master)$ pwd/Administrator@snowdreams1006 MINGW64 / (master)$ cd /f/workspace/testAdministrator@snowdreams1006 MINGW64 /f/workspace/test$ tree.├── cmd└── gitbash2 directories, 0 files
tree.exe
<pre class="brush:php;toolbar:false;">Administrator@snowdreams1006 MINGW64 / (master)$ pwd/Administrator@snowdreams1006 MINGW64 / (master)$ ls usr/bin/tree.exeusr/bin/tree.exe*Administrator@snowdreams1006 MINGW64 / (master)$ ls usr/bin/tree.exeusr/bin/tree.exe*
然而,事情还没有结束,虽然打印当前路径显示的是在
/
git bash
/

事情应该不至于这么复杂,我猜测如果进入到
git sdk

还有一种源码编译安装方式,可以猜想到的是将会比较麻烦,不仅要安装
c
windows
恕再下先行一步,告辞!

但是老司机怎么能收走就走,不是说好一起闯天下得嘛?
然而,心有余而力不足,编译安装再到测试确实是不少挑战,最重要的是,电脑太卡了等不了.
所以,收集到了一些资料方便有条件的小伙伴去研究吧!

mingw
msys2
cygwin
tree
c
tree.exe
c
tree.exe
git bash
.exe
linux
tree
我觉得我还可以再坚持一会,虽然不能从头开始编译生成
tree.exe
tree
tree.exe
说道这里,不得不提一下神奇的 sourceforge 网站,提供源码和下载网站.

前面我们一直在说
mintty
mingw
msys2
cygwin
gnu
gnu
所以我们应该可以从
sourceforge

功夫不负有心人,竟然真的找到了,搜索
gnu
gnuwin32
tree

于是下载二进制文件找到其中的
/bin/tree.exe
/git/usr/bin
git bash
tree
首先清除掉上一步设置的别名,防止干扰以确保此二进制文件真实有效.
代码语言:javascript代码运行次数:0运行复制<pre class="brush:php;toolbar:false;">snowdreams1006@home MINGW64 /g/sublime/test# 切换到 `git` 安装目录$ cd /e/gitsnowdreams1006@home MINGW64 /e/git# 编辑 `bash.bashrc` 配置文件,移除别名$ vim ./etc/bash.bashrcsnowdreams1006@home MINGW64 /e/git# 查看配置文件内容,别名设置已移除$ tail ./etc/bash.bashrc[[ "$-" != *i* ]] && return# Set a default prompt of: user@host, MSYSTEM variable, and current_directory#PS1='\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[35m\]$MSYSTEM\[\e[0m\] \[\e[33m\]\w\[\e[0m\]\n\$ '# Uncomment to use the terminal colours set in DIR_COLORS# eval "$(dircolors -b /etc/DIR_COLORS)"# Fixup git-bash in non login envshopt -q login_shell || . /etc/profile.d/git-prompt.shsnowdreams1006@home MINGW64 /e/git# 刷新配置文件,使其立即生效$ source ./etc/bash.bashrcsnowdreams1006@home MINGW64 /e/git# 移除 `tree` 别名,适用于命令行方式设置而不是文件设置$ unalias treesnowdreams1006@home MINGW64 /e/git# 运行 `tree` 命令,确保已经无法通过别名方式调用系统的 `tree.com` 命令$ treebash: tree: command not found

真的成功添加了
tree.exe
cmd
tree.com
<pre class="brush:php;toolbar:false;">snowdreams1006@home MINGW64 /e/git$ cd /g/sublime/testsnowdreams1006@home MINGW64 /g/sublime/test# 扩展命令 `tree` 帮助信息$ tree.exe --helpusage: tree [-adfghilnpqrstuvxACDFNS] [-H baseHREF] [-T title ] [-L level [-R]] [-P pattern] [-I pattern] [-o filename] [--version] [--help] [--inodes] [--device] [--noreport] [--nolinks] [--dirsfirst] [--charset charset] [--filelimit #] [<directory list>] -a All files are listed. -d List directories only. -l Follow symbolic links like directories. -f Print the full path prefix for each file. -i Don't print indentation lines. -q Print non-printable characters as '?'. -N Print non-printable characters as is. -p Print the protections for each file. -u Displays file owner or UID number. -g Displays file group owner or GID number. -s Print the size in bytes of each file. -h Print the size in a more human readable way. -D Print the date of last modification. -F Appends '/', '=', '*', or '|' as per ls -F. -v Sort files alphanumerically by version. -r Sort files in reverse alphanumeric order. -t Sort files by last modification time. -x Stay on current filesystem only. -L level Descend only level directories deep. -A Print ANSI lines graphic indentation lines. -S Print with ASCII graphics indentation lines. -n Turn colorization off always (-C overrides). -C Turn colorization on always. -P pattern List only those files that match the pattern given. -I pattern Do not list files that match the given pattern. -H baseHREF Prints out HTML format with baseHREF as top directory. -T string Replace the default HTML title and H1 header with string. -R Rerun tree when max dir level reached. -o file Output to file instead of stdout. --inodes Print inode number of each file. --device Print device ID number to which each file belongs. --noreport Turn off file/directory count at end of tree listing. --nolinks Turn off hyperlinks in HTML output. --dirsfirst List directories before files. --charset X Use charset X for HTML and indentation line output. --filelimit # Do not descend dirs with more than # files in them.snowdreams1006@home MINGW64 /g/sublime/test# 原生 `tree.com` 帮助信息$ winpty tree.com /?卷 软件 的文件夹 PATH 列表卷序列号为 000000CA 223E:7300E:\GIT\?无效的路径 - \GIT\?没有子文件夹
虽然原生
cmd
tree.com
tree.exe
tree
如果想要在
git bash
tree
winpty tree.com
cmd
tree.com
winpty cmd //c tree
cmd
tree
Git For Windows
Pacman -S tree
tree
tree
tree.exe
git bash
/usr/bin
tree
git
windows
Git For Windows
windows
Git For Windows
由于
Git For Windows
git
git
Git For Windows
但
git
linux
windows
linux
因此,
Git for Window
gnu
WSL
Windows Subsystem for Linux
正是由于背后千丝万缕的联系,为我们扩展
git bash
基于
cygwin
linux
windows
linux
当然,
cygwin
msys2
mingw
殊途同归,他们的底层架构有些不同,但目的是一致的,都是在
windows
linux
mintty
在终端中调用各自的包管理工具即可轻松扩展第三方命令,此外,由于他们大多数都有
c
所以
git bash
git
Git For Windows
默认
Git For Windows
msys2
Pacman
tree
最后稍微总结本文知识要点:
git bash
cmd
git bash
cmd
winpty
winpty tree.com
git bash
Git for Windows SDK
git bash
msys2
mingw
cygwin
tree.exe
好了,说了这么多,小伙伴们 get 到如何在
git bash
tree
以上就是git 入门教程之 git bash 竟然不支持 tree 命令的详细内容,更多请关注php中文网其它相关文章!
 
                        
                        每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
 
                Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号