1. 首先安裝macports
2. 在 Terminal(終端)應(yīng)用程序中,你可以通過鍵入 port 命令來使用 MacPorts。
port
會(huì)顯示
MacPorts 2.8.1
Entering shell mode... ("help" for help, "quit" to quit)
表示你的 MacPorts 現(xiàn)在正在正常工作。你現(xiàn)在位于 MacPorts 的交互式 shell 模式中,可以在這里執(zhí)行一系列的 MacPorts 命令。
(在這個(gè)模式下,你可以直接輸入 MacPorts 命令,而無需在每個(gè)命令前都輸入 port。例如,你可以直接輸入 installed 來查看已安裝的軟件包,或者輸入 search <軟件包名> 來搜索特定的軟件包。
如果你想退出 MacPorts 的 shell 模式并返回到常規(guī)的命令行,只需輸入 quit。
如果你需要幫助,你可以在 MacPorts shell 模式下輸入 help 來查看可用的命令及其用法。)
3. 輸入 install git。如果你想退出交互式shell模式并返回到常規(guī)的命令行,只需輸入 quit。然后你可以在常規(guī)的命令行中執(zhí)行 sudo port install git 命令。
(1)鍵入
install git
顯示如下
Error: Insufficient privileges to write to MacPorts install prefix.
說明你的 MacPorts shell 模式并未以超級(jí)用戶權(quán)限執(zhí)行,因此無法安裝軟件包。
(MacPorts shell 是一個(gè)交互式命令行環(huán)境,它允許你直接執(zhí)行 MacPorts 命令,無需在每條命令前添加 port。
當(dāng)你在命令行中只輸入 port 并按下回車鍵時(shí),你就進(jìn)入了 MacPorts shell。在這個(gè)環(huán)境中,你可以直接輸入 MacPorts 命令,例如 install git,而無需添加 port,即不需要寫成 port install git。
這種情況說明你在 MacPorts shell 中遇到了權(quán)限問題,這可能意味著這個(gè) shell 沒有以超級(jí)用戶權(quán)限(sudo)運(yùn)行。)
在這種情況下,你可以選擇退出 MacPorts shell 模式并在常規(guī)的命令行中執(zhí)行安裝命令。在 MacPorts shell 中輸入 quit 來退出,然后在常規(guī)的命令行中輸入 sudo port install git 來安裝 git。
(2)鍵入
sudo port install git
顯示如下
Password:
---> Computing dependencies for git
表示 MacPorts 正在計(jì)算安裝 git 所需的依賴包。MacPorts 將會(huì)自動(dòng)處理這些依賴關(guān)系,安裝所有必要的軟件包。
4. MacPorts會(huì)列出的所有為了安裝git而需要的依賴庫。這個(gè)列表看起來可能有些長,但實(shí)際上這是正常的。許多包有著相互的依賴關(guān)系,為了讓git工作,需要確保這些依賴庫都被正確地安裝。最后顯示如下
Continue? [Y/n]:
系統(tǒng)現(xiàn)在問你是否要繼續(xù)進(jìn)行。如果你同意安裝這些依賴庫,你可以輸入 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
-
關(guān)于
db48
:Java和Tcl的綁定現(xiàn)在由db48-java
和db48-tcl
子端口提供。 -
關(guān)于
git
:已將啟用osxkeychain憑據(jù)幫助程序的配置添加到位于/opt/local/etc/gitconfig
的系統(tǒng)范圍內(nèi)的gitconfig中。如果你不想使用此憑據(jù)幫助程序,你可以在自己的個(gè)人git配置文件($HOME/.gitconfig
)中覆蓋此設(shè)置,例如:[credential] helper = some_other_credential_helper
如果你需要更多信息,可以運(yùn)行
git help credentials
命令。 -
關(guān)于
libidn
:GNU libidn2是GNU libidn的后繼。它帶有IDNA 2008和TR46實(shí)現(xiàn),并提供了GNU libidn的兼容層。 -
關(guān)于
libpsl
:libpsl API文檔由libpsl-docs
端口提供。 -
關(guān)于
rsync
:如果你想使用rsyncd服務(wù)器,你必須將/opt/local/etc/rsyncd.conf.example
復(fù)制到rsyncd.conf
并在那里添加你的模塊。關(guān)于更多信息,可以參閱man rsyncd.conf
。
一個(gè)啟動(dòng)項(xiàng)已生成,將有助于使用launchd啟動(dòng)rsync。默認(rèn)情況下,它是禁用的。執(zhí)行以下命令以啟動(dòng)它,并使它在啟動(dòng)時(shí)加載:sudo port load rsync
6. 現(xiàn)在你已經(jīng)在你的macOS上通過MacPorts安裝了git,所以你應(yīng)該能夠在命令行中使用它。你可以通過打開終端并鍵入git --version來檢查它是否已正確安裝。如果你看到git的版本號(hào),那么git應(yīng)該已經(jīng)可以使用了。
7. 克隆遠(yuǎn)程倉庫:這是將遠(yuǎn)程倉庫復(fù)制到本地的操作。命令格式為:git clone [url]。例如:
git clone https://gitee.com/your_username/your_repository.git
“https://gitee.com/username/repo.git”(其中,“username” 是你的 Gitee 用戶名,“repo” 是你的倉庫名)
如果你想克隆 GitHub 上的一個(gè)項(xiàng)目,可以使用
git clone https://github.com/user/repo.git。
現(xiàn)在你的Gitee倉庫應(yīng)該已經(jīng)被克隆到你的本地目錄了。你可以通過cd命令進(jìn)入到那個(gè)目錄,并使用git status命令查看倉庫狀態(tài)。
接下來會(huì)讓你輸入賬戶名和密碼
Username for 'https://gitee.com':
出現(xiàn)以下提示:
警告:您似乎克隆了一個(gè)空倉庫。
說明在你嘗試克隆的 Gitee 倉庫是空的,即這個(gè)倉庫沒有任何文件或者代碼。這就是為什么會(huì)看到 “警告:您似乎克隆了一個(gè)空倉庫?!?的提示。
8. 如何在倉庫中添加代碼?
(1)打開終端,然后使用cd命令進(jìn)入你的Git倉庫目錄。比如你的倉庫是repo,那么你可以輸入 cd repo。
(2)在倉庫中創(chuàng)建一個(gè)新文件。這可以通過各種方式完成。你可以在終端中使用touch命令創(chuàng)建一個(gè)空文件(比如 touch newfile.txt)打開你的新文件,并編寫一些代碼或文本。例如,你可以使用命令nano newfile.txt在終端編輯器中打開文件,并寫入一些內(nèi)容。
(3)除了第(2)步這種方式,還可以直接將寫好的代碼文件復(fù)制到本地的倉庫目錄中。
9. 將代碼文件添加推送到遠(yuǎn)程倉庫
(1)在終端中,使用git add命令將你的新文件添加到Git倉庫。
git add newfile.txt
使用 git add . 命令。
git add .
這條命令將會(huì)把倉庫目錄下的所有新文件和修改過的文件添加到暫存區(qū)。這意味著,Git 現(xiàn)在知道這些文件的存在,并將在下次提交時(shí)包括它們。注意命令中的 “.” 表示當(dāng)前目錄。
(2)使用git commit命令將你的更改提交到倉庫。在這個(gè)命令后面,你需要添加一個(gè)描述你所做更改的信息。git commit -m “your message” 這將會(huì)創(chuàng)建一個(gè)新的提交,其中包含你剛剛添加到暫存區(qū)的所有更改。你應(yīng)該在 “your message” 中包含一個(gè)簡短的消息,描述你做了哪些更改。
git commit -m "Added a new file"
顯示如下:
[master(根提交) 7b0601d] Added a new file
1 file changed, 2 insertions(+)
create mode 100644 newfile.txt
表示成功地創(chuàng)建了一個(gè)新的commit,其中包含你對(duì)newfile.txt的更改。
(3)最后,如果想將你的更改推送到你的Gitee倉庫,可以使用git push命令。
git push origin master
這條命令將你的master分支的更改推送到名為origin的遠(yuǎn)程倉庫。在你克隆倉庫時(shí),Git自動(dòng)設(shè)置了名為origin的遠(yuǎn)程倉庫,它指向你從Gitee克隆的倉庫URL。
當(dāng)你運(yùn)行這條命令時(shí),Git可能會(huì)提示你輸入Gitee賬戶的用戶名和密碼。完成后,你的更改應(yīng)該會(huì)出現(xiàn)在Gitee的倉庫中。
顯示如下
枚舉對(duì)象中: 3, 完成.
對(duì)象計(jì)數(shù)中: 100% (3/3), 完成.
寫入對(duì)象中: 100% (3/3), 243 字節(jié) | 243.00 KiB/s, 完成.
總共 3(差異 0),復(fù)用 0(差異 0),包復(fù)用 0
remote: Powered by GITEE.COM [GNK-6.4]
To https://gitee.com/max-two/202307_-c.git
* [new branch] master -> master
已經(jīng)成功地將你的代碼推送到遠(yuǎn)程倉庫了!這條信息 * [new branch] master -> master 意味著你已經(jīng)在遠(yuǎn)程倉庫中創(chuàng)建了一個(gè)名為 “master” 的新分支,并將你本地的 “master” 分支的更改推送到了這個(gè)新分支。
你現(xiàn)在應(yīng)該可以在 Gitee 倉庫的網(wǎng)頁上看到你的提交和新添加的文件了。
每次在本地修改了文件并希望將這些改動(dòng)提交到 Git,重復(fù)(1)(2)(3)步驟即可。
10. 如果你想要在命令行中查看你的提交歷史,你可以運(yùn)行以下命令:文章來源:http://www.zghlxwxcb.cn/news/detail-743645.html
git log
這將顯示一個(gè)列表,列出了你的所有提交,最新的提交在最上面。每個(gè)提交都會(huì)顯示一個(gè)唯一的SHA哈希(一個(gè)長字符串,如7b0601d),提交者的名字,提交日期,以及提交消息。文章來源地址http://www.zghlxwxcb.cn/news/detail-743645.html
到了這里,關(guān)于git在macOS環(huán)境下的安裝與配置(小白版)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!