你的Mac中可以使用git ,但无法使用gitk,一般就两个原因
- mac原生git版本太低了。
- git-gui未安装
解决办法:重新使用brew安装git
安装git
-
升级brew
brew update
-
安装git
~ brew install git Updating Homebrew... ==> Installing dependencies for git: pcre2 ==> Installing git dependency: pcre2 ==> Downloading https://homebrew.bintray.com/bottles/pcre2-10.35.catalina.bottle ==> Downloading from https://akamai.bintray.com/6a/6a1e59a5db23d684f92d2bf695601 ######################################################################## 100.0% ==> Pouring pcre2-10.35.catalina.bottle.tar.gz 🍺 /usr/local/Cellar/pcre2/10.35: 230 files, 6.0MB ==> Installing git ==> Downloading https://homebrew.bintray.com/bottles/git-2.26.2.catalina.bottle. ==> Downloading from https://akamai.bintray.com/74/74d378f6530877383f38b6d1a923e ######################################################################## 100.0% ==> Pouring git-2.26.2.catalina.bottle.tar.gz ==> Caveats The Tcl/Tk GUIs (e.g. gitk, git-gui) are now in the `git-gui` formula. Bash completion has been installed to: /usr/local/etc/bash_completion.d zsh completions and functions have been installed to: /usr/local/share/zsh/site-functions Emacs Lisp files have been installed to: /usr/local/share/emacs/site-lisp/git ==> Summary 🍺 /usr/local/Cellar/git/2.26.2: 1,470 files, 44.8MB ==> Caveats ==> git The Tcl/Tk GUIs (e.g. gitk, git-gui) are now in the `git-gui` formula. Bash completion has been installed to: /usr/local/etc/bash_completion.d zsh completions and functions have been installed to: /usr/local/share/zsh/site-functions Emacs Lisp files have been installed to: /usr/local/share/emacs/site-lisp/git
-
使用命令查看git版本
~ git git --version git version 2.24.2 (Apple Git-127)
发现git版本没有变化,不是上面安装的2.26.2版本
-
查看当git目录
~ which git /usr/bin/git
发现git目录还是/usr/bin/git ,brew安装目录在/usr/local/bin/git中才对,因为这里的git才是关联了/usr/local/Cellar/git/2.26.2目录
~ ls -l /usr/local/bin/git lrwxr-xr-x 1 username admin 28 5 11 11:19 /usr/local/bin/git -> ../Cellar/git/2.26.2/bin/git ~ ls -l /usr/bin/git -rwxr-xr-x 1 root wheel 31488 3 17 23:42 /usr/bin/git
造成这样情况是我们.zshrc文件没设置好,我们可以运行监测brew
~ brew doctor # 我们可以看到这么一段提示,我用的是zsh,原生的可能会提示echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bash_profile,下面步骤只要把zshrc变为bash_profile即可 Warning: Homebrew's sbin was not found in your PATH but you have installed formulae that put executables in /usr/local/sbin. Consider setting the PATH for example like so: echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.zshrc
根据提示,我们将echo ‘export PATH="/usr/local/sbin:$PATH"’添加到~/.zshrc文件中,并运行source ~/.zshrc生效配置
#Mac原生git ~ which git /usr/bin/git #添加后 echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.zshrc source ~/.zshrc #brew管理的git ~ which git /usr/local/bin/git
再次运行brew doctor发现上面报警消失,我们这时候再检测git版本,发现版本已经正常显示为brew安装的2.26.2版本
~ git --version git version 2.26.2
但此时在运行gitk,发现还是有问题,还需安装一个git-gui插件
~ gitk zsh: command not found: gitk
-
安装git-gui
通过安装git-gui使git带有gitk功能
~ brew install git-gui Updating Homebrew... ==> Installing dependencies for git-gui: tcl-tk ==> Installing git-gui dependency: tcl-tk ==> Downloading https://homebrew.bintray.com/bottles/tcl-tk-8.6.10.catalina.bottle.1.tar.gz ==> Downloading from https://akamai.bintray.com/47/4740b30b97f0308ecc59c1308945c38ddca5d3da ######################################################################## 100.0% ==> Pouring tcl-tk-8.6.10.catalina.bottle.1.tar.gz ==> Caveats tcl-tk is keg-only, which means it was not symlinked into /usr/local, because macOS already provides this software and installing another version in parallel can cause all kinds of trouble. If you need to have tcl-tk first in your PATH run: echo 'export PATH="/usr/local/opt/tcl-tk/bin:$PATH"' >> ~/.zshrc For compilers to find tcl-tk you may need to set: export LDFLAGS="-L/usr/local/opt/tcl-tk/lib" export CPPFLAGS="-I/usr/local/opt/tcl-tk/include" For pkg-config to find tcl-tk you may need to set: export PKG_CONFIG_PATH="/usr/local/opt/tcl-tk/lib/pkgconfig" ==> Summary 🍺 /usr/local/Cellar/tcl-tk/8.6.10: 3,036 files, 51MB ==> Installing git-gui ==> Downloading https://homebrew.bintray.com/bottles/git-gui-2.26.2.catalina.bottle.tar.gz ==> Downloading from https://akamai.bintray.com/27/272b5e5ab0d3f511f640c743053ed8f78bc291e0 ######################################################################## 100.0% ==> Pouring git-gui-2.26.2.catalina.bottle.tar.gz 🍺 /usr/local/Cellar/git-gui/2.26.2: 79 files, 2.2MB ==> Caveats ==> tcl-tk tcl-tk is keg-only, which means it was not symlinked into /usr/local, because macOS already provides this software and installing another version in parallel can cause all kinds of trouble. If you need to have tcl-tk first in your PATH run: echo 'export PATH="/usr/local/opt/tcl-tk/bin:$PATH"' >> ~/.zshrc For compilers to find tcl-tk you may need to set: export LDFLAGS="-L/usr/local/opt/tcl-tk/lib" export CPPFLAGS="-I/usr/local/opt/tcl-tk/include" For pkg-config to find tcl-tk you may need to set: export PKG_CONFIG_PATH="/usr/local/opt/tcl-tk/lib/pkgconfig"
-
现在可以愉快的使用gitk了
~ gitk
常用命令
#
~ git --version
git version 2.26.2
#
~ type -a git
git is /usr/local/bin/git
git is /usr/bin/git
#
~ which git
/usr/bin/git
wasreset 说:
optimum article