使用自制软件版本覆盖 Xcode 中的 git
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10449374/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
override git from Xcode with homebrew version
提问by BetaRide
I've installed XCode and therefore git is there as well. Since i want to have a newer version of git I installed using homebrew.
我已经安装了 XCode,因此 git 也在那里。由于我想要使用自制软件安装的较新版本的 git。
But the homebrew version of git is never called since my PATH looks like this
但是从未调用过 git 的自制版本,因为我的 PATH 看起来像这样
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
which means the /usr/bin/git
is allways called before /usr/local/bin/git
.
这意味着/usr/bin/git
总是在 之前被调用/usr/local/bin/git
。
Is there a way to change that without changing the PATH?
有没有办法在不改变 PATH 的情况下改变它?
回答by GoZoner
Xcode is actually using the GIT that is stored in /Applications/Xcode.app/Contents/Developer/usr/bin
. The same version of GIT gets installed in /usr/bin
when you installed the command line tools as part of Xcode installation. So, you won't be able to change what Xcode is using (unless you are willing to muck with the contents of the Xcode package). If, from a terminal application, you want to use the homebrew-installed GIT then you have two options:
Xcode 实际上使用的是存储在/Applications/Xcode.app/Contents/Developer/usr/bin
. /usr/bin
当您在 Xcode 安装过程中安装命令行工具时,会安装相同版本的 GIT 。因此,您将无法更改 Xcode 使用的内容(除非您愿意使用 Xcode 包的内容)。如果从终端应用程序中,您想使用自制安装的 GIT,那么您有两个选择:
- Reference GIT with the full path as
/usr/local/bin/git ...
For this case you can create an alias likealias mgit=/usr/local/bin/git
and then usemgit ...
from the terminal - Change the path as
PATH=/usr/local/bin:$PATH
either in your.bashrc
or.zshrc
if you use zsh file (or each time you start a terminal at the command line).
- 使用完整路径引用 GIT
/usr/local/bin/git ...
对于这种情况,您可以创建一个别名alias mgit=/usr/local/bin/git
,然后mgit ...
从终端使用 - 将路径更改为
PATH=/usr/local/bin:$PATH
您的.bashrc
或.zshrc
使用 zsh 文件(或每次在命令行启动终端时)。
回答by oppih
Since Xcode hard coded its own version of git which is installed on /Applications/Xcode.app/Contents/Developer/usr/bin/git
, I managed to use this work around trick:
由于 Xcode 对安装在 上的自己的 git 版本进行了硬编码/Applications/Xcode.app/Contents/Developer/usr/bin/git
,因此我设法使用了以下技巧:
change into the Xcode directory:
cd /Applications/Xcode.app/Contents/Developer/usr/bin
rename the Xcode's git like this:
sudo mv ./git ./git-xcode-usr-bin
link my own git which is installed through homebrew:
sudo ln -s /usr/local/bin/git ./git
切换到 Xcode 目录:
cd /Applications/Xcode.app/Contents/Developer/usr/bin
像这样重命名 Xcode 的 git:
sudo mv ./git ./git-xcode-usr-bin
链接我自己通过自制软件安装的 git:
sudo ln -s /usr/local/bin/git ./git
And I did the same thing with /usr/bin/git
我做了同样的事情 /usr/bin/git
This will acctually link /usr/local/Cellar/git/1.8.0/bin/git
(because I'm use git 1.8.0 at the present)
这将实际链接/usr/local/Cellar/git/1.8.0/bin/git
(因为我目前使用的是 git 1.8.0)
Certainly this may cause some other problems, such as when I upgrade the homebrew's verion git in the future, it would not work for me :( and I have to make a new link then.
当然这可能会导致一些其他问题,例如当我将来升级自制软件的 git 版本时,它对我不起作用:(然后我必须创建一个新链接。
I do it like this because I want to solve my own problem here 13177203. And after search StackOverFlow for a long time, I finally got this solution.
我这样做是因为我想在这里解决我自己的问题13177203。并且在StackOverFlow上找了半天,终于得到了这个解决方案。
回答by Paul Wenzel
If you are using fish shellinstead of bash, you can point to your preferred git binary by adding the following to ~/.config/fish/config.fish
.
如果您使用的是fish shell而不是 bash,您可以通过将以下内容添加到 .gitignore 来指向您喜欢的 git 二进制文件~/.config/fish/config.fish
。
function git
/usr/local/bin/git $argv;
end