29、公私鑰的創(chuàng)建于配置github
為了在本地更好的操作遠(yuǎn)程倉(cāng)庫(kù),可以在本地與遠(yuǎn)程倉(cāng)庫(kù)之間配置公私鑰連接,首先可以查看本地是否有公私鑰,如果沒(méi)有可以使用以下命令生成。
$ ls ~/.ssh/ #查看是否存在公私鑰
id_rsa id_rsa.pub known_hosts
ssh-keygen -t rsa -b 4096 -C "your_email@example.com" #如果不存在可使用該命令生成
生成公私鑰后,將公鑰配置到github上。點(diǎn)擊頭像,進(jìn)入Your Profile->SSH and GPG Keys即可進(jìn)入配置公鑰界面
30.在GitHub上創(chuàng)建個(gè)人倉(cāng)庫(kù)
點(diǎn)擊Create a repository鏈接
創(chuàng)建選項(xiàng)界面
創(chuàng)建成功后界面
31.把本地倉(cāng)庫(kù)同步到GitHub
首先將github的倉(cāng)庫(kù)地址配置到本地,可以在箭頭指示的地方獲取倉(cāng)庫(kù)的地址
$ git remote -v
zhineng file:///d/git_learning/.git (fetch)
zhineng file:///d/git_learning/.git (push)
$ git remote add github git@github.com:embedlinux/git_learning.git
$ git remote -v
github git@github.com:embedlinux/git_learning.git (fetch)
github git@github.com:embedlinux/git_learning.git (push)
zhineng file:///d/git_learning/.git (fetch)
zhineng file:///d/git_learning/.git (push)
將本地文件推送到github上,此時(shí)可以知道Jone和temp分支push成功,而master失敗
$ git push github --all
Counting objects: 16, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (9/9), done.
Writing objects: 100% (16/16), 1.29 KiB | 77.00 KiB/s, done.
Total 16 (delta 2), reused 0 (delta 0)
To github.com:embedlinux/git_learning.git
* [new branch] Jone -> Jone
* [new branch] temp -> temp
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'git@github.com:embedlinux/git_learning.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.
此時(shí)由于github上和本地的master分支發(fā)生沖突,因此需要merge
$ git fetch github master #獲取遠(yuǎn)程master分支
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From github.com:embedlinux/git_learning
* branch master -> FETCH_HEAD
* [new branch] master -> github/master
$ git checkout master #本地切換到master分支
Switched to branch 'master'
$ git branch -av
Jone f0b5fe2 Add a file
* master e0326fb Merge three commits
temp b0fc955 Merge three commits
remotes/github/Jone f0b5fe2 Add a file
remotes/github/master 831e37e Initial commit
remotes/github/temp b0fc955 Merge three commits
remotes/zhineng/Jone f0b5fe2 Add a file
$ git merge github/master
fatal: refusing to merge unrelated histories
$ git merge --allow-unrelated-histories github/master #合并遠(yuǎn)程分支
Merge made by the 'recursive' strategy.
LICENSE | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
create mode 100644 LICENSE
$ git push github master #再次push到github上,成功
Counting objects: 2, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 373 bytes | 186.00 KiB/s, done.
Total 2 (delta 0), reused 0 (delta 0)
To github.com:embedlinux/git_learning.git
831e37e..707f0f8 master -> master
32.不同人修改了不同文件如何處理
當(dāng)不同的人工作在同一個(gè)branch,但是修改的是不同文件時(shí),此時(shí)可以使用merge命令對(duì)文件進(jìn)行更新。例如,當(dāng)前在遠(yuǎn)程修改了Jone分支的read1.txt文件。
在本地修改"second.txt"文件
$ git checkout Jone
Switched to branch 'Jone'
Your branch is up to date with 'zhineng/Jone'.
$ echo "Update the file " >> second.txt
$ git add .
$ git commit -m"Update second file"
[Jone 568a695] Update second file
1 file changed, 1 insertion(+)
$ git push github Jone #此時(shí)由于本地文件與遠(yuǎn)程不是同一個(gè)commit,出現(xiàn)問(wèn)題
To github.com:embedlinux/git_learning.git
! [rejected] Jone -> Jone (fetch first)
error: failed to push some refs to 'git@github.com:embedlinux/git_learning.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 fetch github
$ git branch -av
* Jone 568a695 [behind 2] Update second file
master 707f0f8 Merge remote-tracking branch 'github/master'
temp b0fc955 Merge three commits
remotes/github/Jone 139cca2 Update read1.txt
remotes/github/master 707f0f8 Merge remote-tracking branch 'github/master'
remotes/github/temp b0fc955 Merge three commits
remotes/zhineng/Jone 0b88b5a Merge remote-tracking branch 'github/Jone' into Jone
$ git merge remotes/github/Jone
error: Your local changes to the following files would be overwritten by merge:
read1.txt
Please commit your changes or stash them before you merge.
Aborting
$ git merge remotes/github/Jone
Merge made by the 'recursive' strategy.
$ git push github
Counting objects: 6, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (6/6), 624 bytes | 156.00 KiB/s, done.
Total 6 (delta 3), reused 0 (delta 0)
To github.com:embedlinux/git_learning.git
139cca2..00233dd Jone -> Jone
33.不同人修改了同文件的同區(qū)域如何處理
當(dāng)在開(kāi)發(fā)中,不同工作人員對(duì)同一個(gè)文件的相同區(qū)域做了修改時(shí),此時(shí)git進(jìn)行merge就會(huì)發(fā)生錯(cuò)誤,需要手工進(jìn)行merge,確定需要保留的內(nèi)容。首先遠(yuǎn)程修改first1.md文件。
$ echo "Update the file on local" >> first.md #本地也修改該文件
$ git commit -am"Update first.md"
[Jone b6870f1] Update first.md
1 file changed, 1 insertion(+)
$ git fetch github #獲取遠(yuǎn)程倉(cāng)庫(kù)
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From github.com:embedlinux/git_learning
00233dd..c87da97 Jone -> github/Jone
$ git branch -av
* Jone b6870f1 [ahead 3, behind 1] Update first.md
master 707f0f8 Merge remote-tracking branch 'github/master'
temp b0fc955 Merge three commits
remotes/github/Jone c87da97 Update first.md
remotes/github/master 707f0f8 Merge remote-tracking branch 'github/master'
remotes/github/temp b0fc955 Merge three commits
remotes/zhineng/Jone 0b88b5a Merge remote-tracking branch 'github/Jone' into Jone
$ git merge c87da97 #由于遠(yuǎn)程和本地修改相同文件,此時(shí)無(wú)法merge
Auto-merging first.md
CONFLICT (content): Merge conflict in first.md
Automatic merge failed; fix conflicts and then commit the result.
$ vim first.md #手工修改沖突文件
修改前
修改后,同時(shí)保留遠(yuǎn)程和本地的修改
$ git commit -am"Merge conflict file" #再次提交
[Jone c2568ff] Merge conflict file
$ git push github --all #push成功
Counting objects: 6, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (6/6), 601 bytes | 150.00 KiB/s, done.
Total 6 (delta 2), reused 0 (delta 0)
To github.com:embedlinux/git_learning.git
c87da97..c2568ff Jone -> Jone
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線(xiàn),公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性?xún)r(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專(zhuān)為企業(yè)上云打造定制,能夠滿(mǎn)足用戶(hù)豐富、多元化的應(yīng)用場(chǎng)景需求。
網(wǎng)站題目:五、Github的使用(1)-創(chuàng)新互聯(lián)
轉(zhuǎn)載來(lái)源:http://muchs.cn/article14/sppge.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App開(kāi)發(fā)、服務(wù)器托管、手機(jī)網(wǎng)站建設(shè)、企業(yè)建站、微信小程序、做網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容