Git相關(guān)

簡單的Git

1,cd 到項(xiàng)目目錄
2,git init
3,git add .
4,將git創(chuàng)建分支時(shí)的
echo "# Location" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/YQL539/Location.git
git push -u origin master  

復(fù)制到shell里面,點(diǎn)擊enter即可提交到github,中間需要輸入git賬戶名字:YQL539  密碼:密碼

顯示進(jìn)度,成功。

下面是以前寫的,留著做參考:
一,找到git倉庫:finder打開項(xiàng)目,找到隱藏文件.git

終端:Mac顯示隱藏文件:defaults write com.apple.finder AppleShowAllFiles YES,強(qiáng)制退出finder,重新打開finder.

如果項(xiàng)目沒有隱藏的Git文件夾:

1,打開終端,cd 工程目錄,

2,指令:git Init

3,git add .//點(diǎn),第一次提交的時(shí)候需要三四步。

4,git commit -m "Initial commit"

在打開就有g(shù)it文件夾了

二,提交代碼,Xcode source control 里面,commit,

提交之前回滾之前代碼discard all,或者discard 單個(gè)文件

三,提交之后回滾之前版本:

終端,cd 工程目錄.

git reflog //查看提交日志,前面是版本號(hào)

git reset --hard 版本號(hào)//即可回到之前版本,hard強(qiáng)制執(zhí)行,可多次執(zhí)行,回到不同的版本

擴(kuò)展:git config alias.rst 'reset --hard'//增加別名:用rst 取代reset --hard,換git文件夾的時(shí)候即換項(xiàng)目時(shí)候,失效。

四,上傳到gitHub:

1:創(chuàng)建SSH Key

ozil:tmp mesutcd ~ ozil:~ mesut pwd
/Users/mesut
ozil:~ mesutcd .ssh -bash: cd: .ssh: No such file or directory ozil:~ mesut
進(jìn)入當(dāng)前的用戶目錄,波浪線表示的是當(dāng)前目錄。判斷是否已經(jīng)安裝了.ssh,避免默認(rèn)安裝會(huì)覆蓋之前安裝的。明顯當(dāng)前目錄沒有該文件

執(zhí)行創(chuàng)建 ssh key

ssh-keygen -t rsa -C youremail@example.com(你的Github登陸名)
接著都是回車,選擇默認(rèn)的目錄,默認(rèn)的密碼即可

Generating public/private rsa key pair.
Enter file in which to save the key (/Users/mesut/.ssh/id_rsa):
Created directory '/Users/mesut/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/mesut/.ssh/id_rsa.
Your public key has been saved in /Users/mesut/.ssh/id_rsa.pub.
接著可以在用戶主目錄里找到.ssh目錄,里面有id_rsa和id_rsa.pub兩個(gè)文件,這兩個(gè)就是SSH Key的秘鑰對(duì)

ozil:~ mesutcd .ssh ozil:.ssh mesut ls
id_rsa id_rsa.pub
2:在Github設(shè)置ssh key

登陸Github, “Settings”->SSH keys->Add SSH key
title:可以順便填名字
key:在Key文本框里粘貼id_rsa.pub文件的內(nèi)容
點(diǎn)擊add key 配置完成
3:測試本地是否和Github連接上

ozil:.ssh mesutssh -T git@github.com The authenticity of host 'github.com (xxx)' can't be established. RSA key fingerprint is xxx. Are you sure you want to continue connecting (yes/no)? yes 第一次鏈接Github,會(huì)有一個(gè)確認(rèn),需要你確認(rèn)GitHub的Key的指紋信息是否真的來自GitHub的服務(wù)器,輸入yes回車即可。 Warning: Permanently added 'github.com,xxx' (RSA) to the list of known hosts.Hi tanchongshi! You've successfully authenticated, but GitHub does not provide shell access. 4.使用git在本地建立的項(xiàng)目更新到Github 首先在本地初始化一個(gè)git倉庫 由于之前沒有配置用戶名,所以首次commit會(huì)有提示,自動(dòng)建立 設(shè)置方式 git config --global user.name Your Name
git config --global user.email email@example.com 為了把本地庫推到遠(yuǎn)程服務(wù)器,首先需要在Github上面也建一個(gè)項(xiàng)目 在Repository name填上我們的項(xiàng)目名字,description隨便填,別的默認(rèn)。 然后會(huì)生成項(xiàng)目 然后把遠(yuǎn)程項(xiàng)目和本地庫關(guān)聯(lián):cd 到.git 目錄 ozil:hellogithub mesut git remote add origin git@github.com:tanchongshi/hellogithub.git
ozil:hellogithub mesut$ git push -u origin master
Warning: Permanently added the RSA host key for IP address 'XXX' to the list of known hosts.
Counting objects: 3, done.
Writing objects: 100% (3/3), 217 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:tanchongshi/hellogithub.git

  • [new branch] master -> master
    Branch master set up to track remote branch master from origin.
    完成
    配置之后,提交新項(xiàng)目到github 只要cd 進(jìn)入目錄,1,git init 2,git add .3,將github里面新建項(xiàng)目中復(fù)制
    echo "# Location" >> README.md
    git init
    git add README.md
    git commit -m "first commit"
    git remote add origin https://github.com/YQL539/Location.git
    git push -u origin master
    復(fù)制到shell里面,點(diǎn)擊enter即可提交到github

遇到的問題
1:git提交出現(xiàn)只提交了文件夾,沒有文件夾里面的文件的現(xiàn)象
刪除緩存:git rm --cached <dir_name>
添加文件夾:git add dir_name/
重新提交:git commit -m "注釋"
推送:git push
2:提示.git已經(jīng)存在:
cd 到目錄下,ls -a ,看到.git ,rm -rf .git 即可。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容