日本高清免费一本视频100禁_在线不卡欧美精品一区二区三区_国产一区二区好的精华液_中文综合在线_国产啊啊啊视频在线观看_大地资源网免费观看高清

IT之道-艾銻知道

您當前位置: 主頁 > 資訊動態 > 艾銻分享 >

服務器維護linux下git的安裝和使用


2020-05-24 16:01 作者:admin

服務器維護linux下git的安裝和使用

服務器維護小知識最近在使用github,感覺不錯。在windows下,可使用github提供的windows客戶端()。很傻瓜,很方便。如何使用?詳見:。(有圖是王道)最近發現,在公司電腦上安裝github的windows客戶端時,可能由于公司網絡限速和限流量限得太死,怎么也安裝不成功。在家的github windows的圖形客戶端的同步也經常出問題。沒辦法,也只能通過文本界面來連接github了。如果已在windows系統中成功安裝github的客戶端,則除了可使用圖形客戶端外,還可使用github bash這個文本客戶端。在我電腦上,當圖形客戶端同步出現問題時,文客戶端還是能同步成功的。如果安裝不上github的客戶端,還可安裝其他的git bash來連接github,如msysgit ()等。因為以上軟件都是以git為基礎的,所以語法與linux使用的命令相同。
在linux下我僅使用了文本界面,所以安裝了個文本形式的git客戶來連接github。
服務器維護小知識1. 安裝git
我用的是centos系統,在使用yum install git時,系統提示沒有找到git包。所以,僅能通過以下方法來安裝git。方法詳見:。以上方法中有一個問題:方法中給出的git的下載源 似乎無效了,于是,我在網上的這里下載了個git的最新安裝包,安裝到了centos上。Linux下git的官方網址為: ,可能因為我網慢打不開,不知道讀者您那里如何。如果打不開,可以在網上其他地方找找安裝包,應該可以找到的。
服務器維護小知識2. 使用git連接github
使用git連接github時,需要將linux下產生的一個ssh公鑰放到github上。具體步驟詳見:。主要命令有:
ssh-keygen -t rsa -C"[email protected]"
然后系統提示輸入文件保存位置等信息,連續敲三次回車即可,生成的SSH key文件保存在中~/.ssh/id_rsa.pub文件中。
用文本編輯工具打開該文件,在linux下可以用cat命令顯示id_rsa.pub中的內容(cat  ~/.ssh/id_rsa.pub),讓后復制其內容。
接著拷貝.ssh/id_rsa.pub文件內的所以內容,將它粘帖到github帳號管理中的添加SSH key界面中。
注意,使用vim讀取git_home/.ssh/id_rsa.pub中的公鑰內容時,可能會有較多的空格和換行,復制到github網站上時必需刪除。所以建議使用cat來讀取ssh公鑰。將ssh公鑰成功加入github后,可使用命令ssh -T [email protected]來驗證是否成功。如果出現象:hi xxx. You've successfully authenticated, but GitHub does not provide shell access.則說明連接成功。
非常不幸,我未能連接成功。可使用命令ssh -Tv [email protected]來查找failure的原因。通過詳細的debug過程,我發現象我把自己的ssh密鑰信息放到了/home/admin/.ssh/下,而測試時使用的賬戶是root,尋找ssh密鑰的路徑為root/.ssh,所以permission denied的啦。su到admin下,就可以連接成功啦~~
3. 使用git與github管理代碼
3.1 新建一個repository
這里就使用github官網上的教程吧。請保證git的版本至少為1.7.10,否則可能無法成功。詳細如何使用,請參見:https://help.github.com/articles/set-up-git。linux下無法新建一個repo,只能對github中已有的repo進行修改。所以,當要新建一個repo時,必須在github.com上新建,再通過linux下的git向此repo中新添內容。
3.2 修改repo中的代碼
github的官網上也有修改repo代碼的教程。詳情請參見:https://help.github.com/articles/fork-a-repo。簡要步驟如下:
$git clone https://github.com/username/Spoon-Knife.git $cd Spoon-Knife $git add filename.py                          #添加文件到版本庫 $git commit -m 'add filename.py to src'               #提交,產生版本記錄,注意代碼依然在本地 $vim README.md                             #修改Spoon-Knife中的README.md文件內容 $git commit -m 'modify the README.md'                #提交,產生版本記錄,注意代碼依然在本地 $git [remote] rm filename1.py                    #刪除repo中的filename1.py文件 $git commit -m 'delete filename1.py'                  #提交,產生版本記錄,注意代碼依然在本地 $git push origin                             #將修改提交到github上
3.3 常用git命令
git help                                 #可查看git的常用命令 git config --global user.name "Your Name Here"           #設置commit的署名 git config --global user.email "[email protected]"      #設置commit的email git config [--local|--global|--system] --list/-l          #查看本地的global信息 git config [--local|--global|--system] --unset[-all] user.name  #刪除user.name信息。如果user.name對應多個值,可用unset-all來刪除 git remote add XXX https://github.com/username/repo_name.git    #設置github的連接
git clone git://github.com/your_account/aimed_repo.git       #復制一個repo到本地
git remote -v                               #查看本地設置的url連接信息
git status                                 #查看當前工作的
branch git branch                             #查看本地所有的
branch git branch -a                           #查看遠程的所有分支
git branch -d branch_name                        #刪除本地branch_name這一分支
git push origin --delete branch_name                   #刪除名為branch_name的遠程分支
git checkout branch_name                         #切換到名為branch_name的分支上
git chechout -b branch_name                       #在本地新建一個名為branch_nam的分支
git diff test_branch_name                        #查看當前branch與test_branch_name中代碼的區別
git mv filename newfilename                      #文件重命名
git push XXX branch_name                        #上傳指定的branch到遠端
git pull                                  #將遠程上的版本與本地版本進行合并,相當于get fetch + git merge
git reset --hard                             #將剛才進行的git pull所進行的操作取消,恢復本地版本合并前的原貌
4. 如何刪除github上的repository
github頁面上刪除repo的功能比較隱蔽,得在這里表一表。比如,想刪除了一個名為python的repo。則需先點擊進入“python”,單擊“Settings”,找到“Delete this repository”,確認刪除即可。注意,github上的repo刪除后就不能恢復了哦~~
5. git clone/push時出現錯誤提示:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed while accessing ...
服務器維護小知識這是由于ssl認證出問題引起的錯誤。有兩種簡單的解決方法:
1. 使用命令,成功執行后,便可正常使用git clone和git push了
git config --global http.sslVerify false
2. 使用命令,但每次clone 和 push時都需要帶上env的部分。
env GIT_SSL_NO_VERIFY=true git clone https://github.com/XXXX/xxxxx.git
6. git push時出現錯誤non-fast-forward時怎么辦?(來自:)
當要push代碼到git時,出現提示:
error:failed to push some refs to ...
Dealing with “non-fast-forward” errors
From time to time you may encounter this error while pushing:
$ git push origin master  
To ../remote/  
 ! [rejected]        master -> master (non-fast forward)  
error: failed to push some refs to '../remote/'  
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes before pushing again.  See the 'non-fast forward'
section of 'git push --help' for details.
This error can be a bit overwhelming at first, do not fear. Simply put, git cannot make the change on the remote without losing commits, so it refuses the push. Usually this is caused by another user pushing to the same branch. You can remedy this by fetching and merging the remote branch, or using pull to perform both at once.
In other cases this error is a result of destructive changes made locally by using commands like git commit --amend or git rebase. While you can override the remote by adding --force to the push command, you should only do so if you are absolutely certain this is what you want to do. Force-pushes can cause issues for other users that have fetched the remote branch, and is considered bad practice. When in doubt, don’t force-push.



問題(Non-fast-forward)的出現原因在于:git倉庫中已經有一部分代碼,所以它不允許你直接把你的代碼覆蓋上去。于是你有2個選擇方式:
1,強推,即利用強覆蓋方式用你本地的代碼替代git倉庫內的內容
git push -f
2,先把git的東西fetch到你本地然后merge后再push
$ git fetch
$ git merge
這2句命令等價于
$ git pull  
可是,這時候又出現了如下的問題:
上面出現的 [branch "master"]是需要明確(.git/config)如下的內容
[branch "master"]
    remote = origin
merge = refs/heads/master
服務器維護小知識這等于告訴git2件事:
1,當你處于master branch, 默認的remote就是origin。
2,當你在master branch上使用git pull時,沒有指定remote和branch,那么git就會采用默認的remote(也就是origin)來merge在master branch上所有的改變
如果不想或者不會編輯config文件的話,可以在bush上輸入如下命令行:
$ git config branch.master.remote origin  
$ git config branch.master.merge refs/heads/master  
之后再重新git pull下。最后git push你的代碼吧。it works now~
 
IT運維  我們選擇北京艾銻無限
以上文章由北京艾銻無限科技發展有限公司整理



相關文章

IT外包服務
二維碼 關閉
主站蜘蛛池模板: 虎林市| 阜平县| 松溪县| 东平县| 梁平县| 金塔县| 富源县| 文昌市| 平远县| 凌海市| 巴彦县| 德昌县| 台安县| 潞西市| 海伦市| 罗江县| 涞源县| 当阳市| 临汾市| 东兴市| 彭阳县| 连云港市| 越西县| 肃北| 南昌县| 田东县| 苍溪县| 仁怀市| 赤水市| 通江县| 石渠县| 易门县| 崇左市| 阳朔县| 内黄县| 五常市| 柞水县| 永嘉县| 泸水县| 镇江市| 锦屏县|