与 Xcode 分开安装 Git

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10904774/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 00:30:55  来源:igfitidea点击:

Install Git separately from Xcode

xcodemacosgit

提问by Chris Sanderson

Firstly apologies if this is a really simple question but Git is absolutely brand new to me. Basically I've been dabbling with a bit of iOS development for a little while and now have a project idea that I want to start working on and for the first time I'm planning on putting this into source control.

首先很抱歉,如果这是一个非常简单的问题,但 Git 对我来说绝对是全新的。基本上,我已经涉足了一段时间的 iOS 开发,现在有了一个我想开始工作的项目想法,这是我第一次计划将其放入源代码控制中。

Now I know Xcode 4 has some Git integration but I've spotted a couple of posts that suggest the integration isn't that great and it's better to do it the command line way.

现在我知道 Xcode 4 有一些 Git 集成,但我发现一些帖子表明集成不是那么好,最好以命令行方式进行。

So, I've been following instructions here http://git-scm.com/book/en/Getting-Started-Installing-Gitand I've downloaded version 1.7.10.3 for Mac and ran the install.

所以,我一直在按照http://git-scm.com/book/en/Getting-Started-Installing-Git 的说明进行操作,我已经下载了 Mac 版 1.7.10.3 并运行了安装。

However when I run git --version I get version 1.7.4.4 which is the version that was installed with Xcode I assume?

但是,当我运行 git --version 时,我得到版本 1.7.4.4,这是我假设与 Xcode 一起安装的版本?

My question is, how do I make use of my new version 1.7.10.3? The plan is to learn to use Git via command tools and set up a central repository on a server I have at home, then have local copies on my laptop.

我的问题是,如何使用我的新版本 1.7.10.3?计划是通过命令工具学习使用 Git,并在我家里的服务器上设置一个中央存储库,然后在我的笔记本电脑上拥有本地副本。

As I say I'm really new to this, so a quick step by step idiots guide would be helpful. I have searched and tried to find details here and on google but other than the suggestion to use Git outside of Xcode I've not found out exactly how to do it.

正如我所说的,我对此非常陌生,因此快速的分步白痴指南会有所帮助。我已经搜索并试图在这里和谷歌上找到详细信息,但除了建议在 Xcode 之外使用 Git 之外,我还没有找到确切的方法。

Any advice, or links to a decent tutorial that covers this would be very much appreciated.

非常感谢任何建议或指向涵盖此内容的体面教程的链接。

Update:

更新:

I've changed the path to the new path in .bash_profile (/usr/local/git/bin) and now get git version 1.7.7.5 (Apple Git-26). This still appears to be the wrong version (although this could be me being dense). I downloaded the installer for OSX from the above link. Should I be doing something else. I want to play around with the command line tools so I can get a proper understanding

我已将路径更改为 .bash_profile (/usr/local/git/bin) 中的新路径,现在获得 git 版本 1.7.7.5 (Apple Git-26)。这似乎仍然是错误的版本(尽管这可能是我太密集了)。我从上面的链接下载了 OSX 的安装程序。我该不该做点别的。我想玩转命令行工具,这样我才能得到正确的理解

Update 2:

更新 2:

I'm now also trying MacPorts as recommended in the article. This seems to be downloading a lot more than just Git though

我现在也在尝试文章中推荐的 MacPorts。不过,这似乎下载的不仅仅是 Git

回答by GoZoner

Xcode installs git in /Applications/Xcode.app/... but if you run 'Install Command Tools' then git gets installed also in /usr/bin/git. Xcode uses its private version in Xcode.app. If you installed git in /usr/local/git/bin then you need to include that directory in your PATH. You should have a .bashrc file (or equivalent for whatever shell you are using). Add

Xcode 将 git 安装在 /Applications/Xcode.app/... 但如果您运行“安装命令工具”,那么 git 也会安装在 /usr/bin/git 中。Xcode 在 Xcode.app 中使用其私有版本。如果您在 /usr/local/git/bin 中安装了 git,那么您需要将该目录包含在您的 PATH 中。您应该有一个 .bashrc 文件(或与您使用的任何 shell 相同的文件)。添加

PATH=/usr/local/git/bin:$PATH     # your shell might use different syntax.

to that file 'rc' file.

到那个文件 'rc' 文件。

Also, note that Xcode would allow you to accomplish your goal of setting up a remote at home while maintaining a local copy on your laptop. Go to the Xcode 'organizer' and click 'repositories'. There you will find all your machine's Git repositories. Choose one, select the 'remotes' folder and then '+' to add your home remote. I use Xcode this way.

另请注意,Xcode 将允许您实现在家中设置遥控器的目标,同时在笔记本电脑上维护本地副本。转到 Xcode 的“组织者”并单击“存储库”。在那里你会找到你机器的所有 Git 存储库。选择一个,选择“遥控器”文件夹,然后选择“+”以添加您的家庭遥控器。我以这种方式使用 Xcode。

回答by Daishi

Credits goes to @GoZoner for the answer. I'm just summing up everything.

感谢@GoZoner 的回答。我只是总结一切。

Download official git installer from : http://git-scm.com/download/mac

从以下位置下载官方 git 安装程序:http: //git-scm.com/download/mac

Install and add its directory to your path : echo "PATH=/usr/local/git/bin:\$PATH" >> ~/.bash_profile source ~/.bash_profile

安装并将其目录添加到您的路径中: echo "PATH=/usr/local/git/bin:\$PATH" >> ~/.bash_profile source ~/.bash_profile

回答by Tony Barajas

The best way is:

最好的办法是:

step 1:

第1步:

Install homebrew on your mac this is the official website Homebrew homepage

在你的 mac 上安装 homebrew 这是官方网站Homebrew 主页

From a Terminal prompt:

从终端提示:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

step 2:

第2步:

From a terminal prompt

从终端提示

brew install git