在macos环境下安装配置git(小白版)
时间:2025-06-24 12:38:55 阅读(143)
在这种情况下你可以选择退出 MacPorts shell 安装命令在常规命令行中执行。在 MacPorts shell 中输入 quit 退出,然后在常规命令行中输入 sudo port install git 来安装 git。
(2)键入。
sudo port install git。
显示如下。
Password:---> Computing dependencies for git。
表示 MacPorts 正在计算安装 git 所需的依赖包。MacPorts 这些依赖关系将自动处理安装所有必要的软件包。
4.。Macports将列出安装git所需的所有依赖库。这个列表可能看起来有点长,但事实上,这是正常的。很多包都有相互依赖的关系,为了让git工作确保所有这些依赖库都正确安装。最后显示如下。
Continue? [Y/n]:。
如果你同意安装这些依赖库,系统现在问你是否想继续。c;你可以输入 Y 然后按回车。
5.。这是您安装git和其他依赖库,MacPorts提供的一些重要信息和提示。(可以忽略)。
---> Some of the ports you installed have notes: db48 has the following notes: The Java and Tcl bindings are now provided by the db48-java and db48-tcl subports. git has the following notes: Configuration to enable the osxkeychain credential helper has been added to the system-wide gitconfig at /opt/local/etc/gitconfig. If you do not wish to use this credential helper, you can override this setting in your own personal git config file ($HOME/.gitconfig) with e.g. [credential] helper = some_other_credential_helper For more information, run git help credentials libidn has the following notes: GNU libidn2 is the successor of GNU libidn. It comes with IDNA 2008 and TR46 implementations and also provides a compatibility layer for GNU libidn. libpsl has the following notes: libpsl API documentation is provided by the port 'libpsl-docs'. rsync has the following notes: To use the rsyncd server you must copy /opt/local/etc/rsyncd.conf.example to rsyncd.conf and add your modules there. See 'man rsyncd.conf' for more information. A startup item has been generated that will aid in starting rsync with launchd. It is disabled by default. Execute the following command to start it, and to cause it to launch at startup: sudo port load rsync。
- 关于
db48。
:Java和Tcl的绑定现在由db48-java。
和。db48-tcl。
提供子端口。 - 关于。
git。
:已将osxkeychain用于帮助程序的配置添加到位。/opt/local/etc/gitconfig。
gitconfig在系统范围内。如果您不想使用此凭证来帮助程序,您可以在自己的个人git配置文件($HOME/.gitconfig。
)中覆盖此设置例如:
[credential] helper = some_other_credential_helper。
如果你需要更多的信息可以运行。git help credentials。
命令。
- 关于。
libidn。
:GNU libidn2GNUUIBidn libidn的后继。它有IDNA 2008年和TR46实现并提供GNU libidn的兼容层。 - 关于。
libpsl。
:libpsl API文档由。libpsl-docs。
端口提供。 - 关于。
rsync。
:如果您想使用rsyncd服务器,你必须做到。//opt/local/etc/rsyncd.conf.example。
复制到。rsyncd.conf。
并在那里添加您的模块。更多信息,可以参阅。man rsyncd.conf。
。
一个启动项已经生成,将有助于使用launchd启动rsync。默认情况下它是禁止的。执行下列命令启动,启动时加载:
sudo port load rsync。
6.。现在你已经通过MacPorts在你的macos上安装了git,所以你应该能够在命令行中使用它。您可以打开终端并输入gitt。 --version检查它是否安装正确。如果您看到git版本号,那么git应该已经可以用了。
7.。克隆远程仓库#xff1a;这是将远程仓库复制到当地的操作。命令格式为:git clone [url]。例如:
git clone https://gitee.com/your_username/your_repository.git。
“https://gitee.com/username/repo.git"(其中,“username” 是你的 Gitee 用户名,“repo” 是你的仓库名)
假如你想克隆 GitHub 一个项目,可以使用。
git clone https://github.com/user/repo.git。
现在你的Gitee仓库应该已经克隆到你的本地目录了。您可以通过cd命令进入目录,使用git status命令检查仓库状态
接下来,您将输入帐户名和密码。
Username for 'https://gitee.com':。
以下提示:
警告:你似乎克隆了一个空仓库。
说明你在尝试克隆 Gitee 仓库是空的,也就是说,这个仓库没有任何文件或代码。这就是为什么会看到它。 "警告:你似乎克隆了一个空仓库。” 的提示。
8.。如何在仓库中添加代码?
(1)打开终端然后使用cd命令进入您的Git仓库目录。例如,您的仓库是repo,然后就可以输入了 cd repo。
(2)在仓库里创建新文件。这可以通过各种方式完成。您可以使用touch命令在终端中创建空文件(比如 touch newfile.txt)打开你的新文件,并编写一些代码或文本。例如,可以使用命令nanono newfile.txt在终端编辑器中打开文件,并写一些内容
(3)除了第(2)步这种方式,编写的代码文件也可以直接复制到当地的仓库目录。
9.。添加并推送代码文件到远程仓库
(1)终端,使用git add命令在Git仓库添加您的新文件。
git add newfile.txt。
使用 git add . 命令。
git add .。
这个命令将列出仓库目录。所有。将新文件和修改后的文件添加到临时存储区。这意味着,Git 现在我们知道这些文件的存在,并且将包括在下一次提交中。注意命令中的内容 “.” 表示当前目录
(2)使用git commit命令将您的更改提交到仓库。在此命令后,您需要添加一个信息来描述您所做的改变。git commit -m “your message” 这将创建一个新的提交,它包括你刚刚添加到暂存区的所有变化。你应该在那里 “your message” 它包含一个简短的消息,描述你做了什么改变。
git commit -m "Added a new file"
显示如下:
[master(提交) 7b0601d] Added a new file 1 file changed, 2 insertions(+) create mode 100644 newfile.txt。
成功地创建了一个新的commit,其中包括你对newfile.txt的变化。
(3)最后,如果你想把你的变化推到Giteee仓库,可使用git push命令。
git push origin master。
这个命令将您的master分支的更改推送到名为origin的远程仓库。克隆仓库时,Git自动设置了远程仓库,名为originc;它指向你从Gitee克隆的仓库URL。
当您执行此命令时,Git可能会提示您输入Gitee账户的用户名和密码。完成后,你的变化应该出现在Gitee的仓库里。
显示如下。
枚举对象: 3, 完成.对象计数: 100% (3/3), 完成.写入对象: 100% (3/3), 243 字节 | 243.00 KiB/s, 完成.总共 3(差异 0),复用 0(差异 0),包复用 0remote: Powered by GITEE.COM [GNK-6.4]To https://gitee.com/max-two/202307_-c.git * [new branch] master -> master。
您的代码已成功推送到远程仓库!这条信息 * [new branch] master -> master 这意味着你已经在远程仓库里创建了一个名字 “master” 新分支,把你当地的 “master” 分支的变化被推到了这个新分支。
你现在应该可以在那里了 Gitee 您的提交和新添加的文件出现在仓库的网页上。
每次在当地修改文件,我都希望提交这些变更 Git,重复(1)(2)(3)步骤即可。
10.。如果您想在命令行中查看您的提交历史,您可以操作以下命令:
git log。
这将显示列表,列出你所有的提交,最新提交在上面。每次提交都会显示唯一的SHA哈希(长字符串7b0601d),提交人姓名,提交日期以及提交信息。