首先:搭建了git平臺(tái),那就有一個(gè)屬于你們自己的網(wǎng)址 比如:http://101.***.***.***:8088,(打開(kāi)會(huì)進(jìn)入一個(gè)登錄頁(yè)面的)
如下圖:
圖一:

圖二:

圖三:

圖四:

上面的圖片好像需要一個(gè)key? 那么問(wèn)題就就來(lái)了,key 怎么獲取呢
下面我講一一介紹
在圖三中,
《點(diǎn)擊上面圖片 上的? add an SSH key 》,會(huì)進(jìn)入到一個(gè)頁(yè)面,此頁(yè)面是 添加SSH key 的說(shuō)明,不過(guò)是英文的,自己可以去百度翻譯下,中文的可以自己去看其他的博客
比如參考博客:http://blog.163.com/www_iloveyou_com/blog/static/2116583722013111113954760/
我們可以通過(guò)命令行來(lái)生成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$
最后得到了兩個(gè)文件:id_rsa和id_rsa.pub:在此目錄下,自己可以搜到到,下面會(huì)用到的哦
Your identification has been saved in /Users/administrator/.ssh/id_rsa.
Your public key has been saved in /Users/administrator/.ssh/id_rsa.pub.
然后自己去上面圖片顯示的頁(yè)面 去 添加 SSH key
保存以后,再次刷新 第二個(gè)頁(yè)面時(shí),沒(méi)有出現(xiàn)
you won't be able to push project code via SSH until you add an SSH key to you profilesh
說(shuō)明ssh key 已經(jīng)添加好了(當(dāng)然,有些git 不添加也可以去使用,當(dāng)你的git 服務(wù)器沒(méi)有使用SSH ,使用的是http時(shí)候,就不需要配置ssh)
-------------------------------------------------------
上面的事情就可以告一段落了,如果這樣就認(rèn)為這是一個(gè)和諧社會(huì),那你就想多了
不是說(shuō)好的 git 管理代碼的使用說(shuō)明,好像什么都沒(méi)有說(shuō)呀
哈哈哈......
我們繼續(xù)
下面將隆重介紹 git 的使用方法 及其 常見(jiàn)問(wèn)題的解決方案:
********************** 功能:上傳項(xiàng)目到 git **********************
前提: 把項(xiàng)目里面 自帶的git 文件刪除,如果不刪除,輸入命令git init 時(shí),
會(huì)顯示Reinitialized existing Git repository in.. ..
再輸入 git status 時(shí),
On branch masternothing to commit, working directory clean(翻譯:無(wú)提交,工作目錄清潔)
當(dāng)你把項(xiàng)目修改過(guò),執(zhí)行第一步中的? cd /Users/administrator/Desktop/BYM3.4? 、第二步git status ,后此時(shí)會(huì)出現(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$
上述是比較順利的 中間沒(méi)有什么插曲,但是,時(shí)間如果有這么多的一番風(fēng)順,那么博客就不用寫(xiě)著么多了,
下面我將介紹一下 常見(jiàn)的問(wèn)題:
問(wèn)題一
輸入如下命令時(shí):
administrator:BYM3.4 administrator$git push origin master
錯(cuò)誤:
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 對(duì)源代碼進(jìn)行push到gitHub時(shí)可能會(huì)出錯(cuò),信息如下
此時(shí)很多人會(huì)嘗試下面的命令把當(dāng)前分支代碼上傳到master分支上
$ git push -u origin master
但依然沒(méi)能解決問(wèn)題
出現(xiàn)錯(cuò)誤的主要原因是github中的README.md文件不在本地代碼目錄中
可以通過(guò)如下命令進(jìn)行代碼合并【注:pull=fetch+merge]
git pull --rebase origin master
執(zhí)行上面代碼后可以看到本地代碼庫(kù)中多了README.md文件
問(wèn)題二
輸入如下命令時(shí):
administrator:GitTestAAA administrator$ git remote add origin git@iZ23bbkx4wiZ:test/WGZY.git
錯(cuò)誤如下:
fatal: remote origin already exists.
解決方案:
1、先輸入$ git remote rm origin
2、再輸入$ git remote add origin git@github.com:djqiang/gitdemo.git 就不會(huì)報(bào)錯(cuò)了?。ǜ鶕?jù)自己的服務(wù)器的地址來(lái))
3、如果輸入$ git remote rm origin 還是報(bào)錯(cuò)的話(huà),error: Could not
remove config section 'remote.origin'. 我們需要修改gitconfig文件的內(nèi)容
4、找到你的github的安裝路徑,我的是C:\Users\ASUS\AppData\Local\GitHub\PortableGit_ca477551eeb4aea0e4ae9fcd3358bd96720bb5c8\etc
5、找到一個(gè)名為gitconfig的文件,打開(kāi)它把裡面的
[remote "origin"]那一行
刪掉就好了!
問(wèn)題三
輸入命令如下:
administrator:GitTestAAA administrator$git init
錯(cuò)誤:
Reinitialized existing Git repository in /Users/administrator/Desktop/GitTestAAA/.git/
解決方案: 在前面已經(jīng)說(shuō)了
問(wèn)題四:
輸入命令如下:(clone 項(xiàng)目代碼)
git clone http://git.baiyimao.com/Test/iOS.git
錯(cuò)誤:
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
解決方案:原因是 沒(méi)有 初始化git,輸入命令行即可 git init ,然后再去clone 項(xiàng)目(把項(xiàng)目clone到一個(gè)指定的文件里面 做法是
cd /Users/administrator/Desktop/testProject01
)
其他問(wèn)題
在 Mac 文件的文件名前添加 . 即可使文件隱藏
也可以在終端里面能用命令來(lái)控制
顯示Mac隱藏文件的命令:defaults write com.apple.finder AppleShowAllFiles YES
隱藏Mac隱藏文件的命令:defaults write com.apple.finder AppleShowAllFiles NO
命令運(yùn)行后需要按 Command Option Esc 選中 Finder 然后點(diǎn)一下 重新開(kāi)啟 就 Ok 了
注:
但別人把項(xiàng)目? clone 下來(lái)以后,然后與 remote origin (遠(yuǎn)程倉(cāng)庫(kù))重新連接,這樣就可進(jìn)行多人管理代碼了:git remote add origin git@iZ23bbkx4wiZ:baiyimaoDevolep/WGZY.git
參考博客: