<git 管理代碼>使用方法 & 常見問題解決方案

首先:搭建了git平臺,那就有一個屬于你們自己的網址 比如:http://101.***.***.***:8088,(打開會進入一個登錄頁面的)

如下圖:

圖一:

圖二:

圖三:



圖四:


s

上面的圖片好像需要一個key? 那么問題就就來了,key 怎么獲取呢

下面我講一一介紹



在圖三中,

《點擊上面圖片 上的? add an SSH key 》,會進入到一個頁面,此頁面是 添加SSH key 的說明,不過是英文的,自己可以去百度翻譯下,中文的可以自己去看其他的博客

比如參考博客:http://blog.163.com/www_iloveyou_com/blog/static/2116583722013111113954760/

我們可以通過命令行來生成SSH key

administrator:~ administrator$ cd ~/.ssh

-bash: cd: /Users/administrator/.ssh: No such file or directory

administrator:~ administrator$ config? id_rsa? id_rsa.pub? known_hosts

-bash: config: command not found

administrator:~ administrator$ ssh-keygen -t rsa -C "添加自己的郵箱"

Generating public/private rsa key pair.

Enter file in which to save the key (/Users/administrator/.ssh/id_rsa):

Created directory '/Users/administrator/.ssh'.

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /Users/administrator/.ssh/id_rsa.

Your public key has been saved in /Users/administrator/.ssh/id_rsa.pub.

The key fingerprint is:

SHA256:IdZ/tJj2Sf/vVcEaABT268Clacr58pxEx0oQs+Fn6CU 1208535097@q q.com

The key's randomart image is:

+---[RSA 2048]----+

|? ? ? +.=o.? ? |

|? ? ? ..B . . .? |

|? ? ? oEo+ o.. o |

|? ? ...Bo=+..o .|

|? ? ? .SO=++.? .|

|? ? ? . *.=+ o? .|

|? ? ? + o .o . .|

|? ? ? .+ .? ? ..|

|? ? ? ? o=? ? .=|

+----[SHA256]-----+

administrator:~ administrator$ pbcopy < ~/.ssh/id_rsa.pub

administrator:~ administrator$ git add .

fatal: Not a git repository (or any of the parent directories): .git

administrator:~ administrator$ git config --global user.name "mjq"

administrator:~ administrator$

最后得到了兩個文件:id_rsa和id_rsa.pub:在此目錄下,自己可以搜到到,下面會用到的哦

Your identification has been saved in /Users/administrator/.ssh/id_rsa.

Your public key has been saved in /Users/administrator/.ssh/id_rsa.pub.

然后自己去上面圖片顯示的頁面 去 添加 SSH key


保存以后,再次刷新 第二個頁面時,沒有出現(xiàn)

you won't be able to push project code via SSH until you add an SSH key to you profilesh

說明ssh key 已經添加好了(當然,有些git 不添加也可以去使用,當你的git 服務器沒有使用SSH ,使用的是http時候,就不需要配置ssh)

-------------------------------------------------------

上面的事情就可以告一段落了,如果這樣就認為這是一個和諧社會,那你就想多了

不是說好的 git 管理代碼的使用說明,好像什么都沒有說呀

哈哈哈......

我們繼續(xù)

下面將隆重介紹 git 的使用方法 及其 常見問題的解決方案:


********************** 功能:上傳項目到 git **********************

前提: 把項目里面 自帶的git 文件刪除,如果不刪除,輸入命令git init 時,

會顯示Reinitialized existing Git repository in.. ..

再輸入 git status 時,

On branch masternothing to commit, working directory clean(翻譯:無提交,工作目錄清潔)

當你把項目修改過,執(zhí)行第一步中的? cd /Users/administrator/Desktop/BYM3.4? 、第二步git status ,后此時會出現(xiàn)On branch masterChanges to be committed:? (use "git reset HEAD..." to unstage)modified:? asd.xcodeproj/project.pbxprojnew file:? asd/dd.hnew file:? asd/dd.m(這些文件是你修改的文件,不用管它)執(zhí)行第三步就好,然后,繼續(xù)執(zhí)行就可以了



第一步:

administrator:~ administrator$ cd /Users/administrator/Desktop/BYM3.4

?administrator:BYM3.4 administrator$ git init

Initialized empty Git repository in /Users/administrator/Desktop/BYM3.4/.git/

第二步:

administrator:BYM3.4 administrator$git status

On branch masterInitial commitUntracked files:? (use "git add..." to include in what will be committed)

WGZY.xcodeproj/

WGZY/

WGZYTests/

nothing added to commit but untracked files present (use "git add" to track)

第三步:

administrator:BYM3.4 administrator$ git add .

第四步:

administrator:BYM3.4 administrator$git commit -m "first commit"

[master (root-commit) c016112] first commit

1737 files changed, 111203 insertions(+)

create mode 100755 WGZY.xcodeproj/project.pbxproj

create mode 100755 WGZY.xcodeproj/project.xcworkspace/contents.xcworkspacedata

create mode 100755 WGZY.xcodeproj/project.xcworkspace/xcshareddata/WGZY.xccheckout

….(省略很多)

create mode 100755 WGZYTests/Info.plist

create mode 100755 WGZYTests/WGZYTests.m

第五步:

administrator:BYM3.4 administrator$ git remote add origin http://git.baiyimao.com/baiyimaoDevolep/iOS.git

第六步:

administrator:BYM3.4 administrator$ git push origin master

Counting objects: 1873, done.

Delta compression using up to 4 threads.

Compressing objects: 100% (1858/1858), done.

Writing objects: 100% (1873/1873), 92.43 MiB | 411.00 KiB/s, done.

Total 1873 (delta 312), reused 0 (delta 0)

To http://git.baiyimao.com/baiyimaoDevolep/iOS.git

* [new branch]? ? ? master -> master

administrator:BYM3.4 administrator$

上述是比較順利的 中間沒有什么插曲,但是,時間如果有這么多的一番風順,那么博客就不用寫著么多了,

下面我將介紹一下 常見的問題:

問題一

輸入如下命令時:

administrator:BYM3.4 administrator$git push origin master

錯誤:

To http://git.baiyimao.com/baiyimaoDevolep/WGZY.git

! [rejected]? ? ? ? master -> master (fetch first)

error: failed to push some refs to 'http://git.baiyimao.com/baiyimaoDevolep/WGZY.git'

hint: Updates were rejected because the remote contains work that you do

hint: not have locally. This is usually caused by another repository pushing

hint: to the same ref. You may want to first integrate the remote changes

hint: (e.g., 'git pull ...') before pushing again.

hint: See the 'Note about fast-forwards' in 'git push --help' for details.

解決方案:

在使用git 對源代碼進行push到gitHub時可能會出錯,信息如下

此時很多人會嘗試下面的命令把當前分支代碼上傳到master分支上

$ git push -u origin master

但依然沒能解決問題

出現(xiàn)錯誤的主要原因是github中的README.md文件不在本地代碼目錄中

可以通過如下命令進行代碼合并【注:pull=fetch+merge]

git pull --rebase origin master

執(zhí)行上面代碼后可以看到本地代碼庫中多了README.md文件

問題二

輸入如下命令時:

administrator:GitTestAAA administrator$ git remote add origin git@iZ23bbkx4wiZ:test/WGZY.git

錯誤如下:

fatal: remote origin already exists.

解決方案:

1、先輸入$ git remote rm origin

2、再輸入$ git remote add origin git@github.com:djqiang/gitdemo.git 就不會報錯了?。ǜ鶕约旱姆掌鞯牡刂穪恚?/p>

3、如果輸入$ git remote rm origin 還是報錯的話,error: Could not

remove config section 'remote.origin'. 我們需要修改gitconfig文件的內容

4、找到你的github的安裝路徑,我的是C:\Users\ASUS\AppData\Local\GitHub\PortableGit_ca477551eeb4aea0e4ae9fcd3358bd96720bb5c8\etc

5、找到一個名為gitconfig的文件,打開它把裡面的

[remote "origin"]那一行

刪掉就好了!

問題三

輸入命令如下:

administrator:GitTestAAA administrator$git init

錯誤:

Reinitialized existing Git repository in /Users/administrator/Desktop/GitTestAAA/.git/

解決方案: 在前面已經說了

問題四:

輸入命令如下:(clone 項目代碼)

git clone http://git.baiyimao.com/Test/iOS.git

錯誤:

Username for 'http://git.baiyimao.com': 123456789@qq.com

Password for 'http://739929409@qq.com@git.baiyimao.com':

remote: HTTP Basic: Access denied

fatal: Authentication failed for 'http://git.baiyimao.com/test/iOS.git/'

fatal: not in a git directory

解決方案:原因是 沒有 初始化git,輸入命令行即可 git init ,然后再去clone 項目(把項目clone到一個指定的文件里面 做法是

cd /Users/administrator/Desktop/testProject01

其他問題

在 Mac 文件的文件名前添加 . 即可使文件隱藏

也可以在終端里面能用命令來控制

顯示Mac隱藏文件的命令:defaults write com.apple.finder AppleShowAllFiles YES

隱藏Mac隱藏文件的命令:defaults write com.apple.finder AppleShowAllFiles NO

命令運行后需要按 Command Option Esc 選中 Finder 然后點一下 重新開啟 就 Ok 了

注:

但別人把項目? clone 下來以后,然后與 remote origin (遠程倉庫)重新連接,這樣就可進行多人管理代碼了:git remote add origin git@iZ23bbkx4wiZ:baiyimaoDevolep/WGZY.git

參考博客:

http://www.cocoachina.com/ios/20140524/8536.html

http://blog.csdn.net/csucfl/article/details/50403425

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

相關閱讀更多精彩內容

  • 1.git的安裝 1.1 在Windows上安裝Git msysgit是Windows版的Git,從https:/...
    落魂灬閱讀 12,850評論 4 54
  • Spring Cloud為開發(fā)人員提供了快速構建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,697評論 19 139
  • 1. 安裝 Github 查看是否安裝git: $ git config --global user.name "...
    Albert_Sun閱讀 13,863評論 9 163
  • 之一 月夜 不眠之夜,姑娘 你是我一生的痛疼與傷口 當如水的月光撥滿大地 我便走進了一個無形的陷阱 一個銀色的童話...
    閑不語閱讀 661評論 2 2
  • 張愛玲說:也許每一個男子全都有過這樣的兩個女人,至少兩個。娶了紅玫瑰,久而久之,紅的變了墻上的一抹蚊子血,白的還是...
    DJ陳牧閱讀 576評論 0 2

友情鏈接更多精彩內容