git安裝使用及常見問題
阿新 • • 發佈:2018-11-19
LK這兩天在弄git這玩意,以後就用Lk來稱呼自己了。可以向遠端倉庫提 交專案和程式碼了,也可以從遠端倉庫擋專案了。
一 。實現這些之前你要先下載git,下載地址:http://git-scm.com/download/win,
下載完成以後,預設安裝就行。
可以看到有Bash 有沒有很激動,以後經常會用到。
二 。接下來建立遠端倉庫,我用的是github
註冊完賬號登入點選箭頭所指的按鈕,進入頁面建立自己的倉庫,輸入倉庫名直接建立就行。
新建倉庫什麼都沒有,你可以右擊滑鼠新建gitbush視窗,照著上面的命令執行,重新整理你的github會看到多了一個檔案。
三.具體命令我是參照https://www.yiibai.com/git/git-quick-start.html 執行的,挺全的適合新手
四.總結一下我遇到的問題
fatal: not a git repository (or any of the parent directories): .git
這個錯是你沒事 git init 這個命令用於初始化現有倉庫
你使用push命令時可能會遇到以下問題
[email protected] MINGW64 /e/git (master)(原因可能是你在本地(或者伺服器上)沒有生成ssh key)
$ git push origin master
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
[email protected] MINGW64 /e/git (master)
$ git remote add origin [email protected]:TDYRZ/yrz.git #新增一個新的遠端庫
[email protected] MINGW64 /e/git (master)
$ git push origin master
The authenticity of host 'github.com (192.30.253.112)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? y
Please type 'yes' or 'no': yes
Warning: Permanently added 'github.com,192.30.253.112' (RSA) to the list of known hosts.
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
[email protected] MINGW64 /e/git (master)
$ cd ~/.ssh
[email protected] MINGW64 ~/.ssh
$ ll #來檢視是否有檔案id_rsa以及檔案id_rsa.pub
[email protected] MINGW64 ~/.ssh
$ ls
known_hosts
[email protected] MINGW64 ~/.ssh
$ ssh-keygen -t rsa -C "@163.com" #生成你的ssh key
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/Administrator/.ssh/id_rsa.
Your public key has been saved in /c/Users/Administrator/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:iZUsywqMgejyYPSY18L+z+dgNOARCIlrU68szXjO294 [email protected]
The key's randomart image is:
|..o .. |
|+. o .. . |
|+o. .o. + |
|+*= ooo= . |
|==O=.o+oS |
|o=oB... . |
| *.. o |
| oo + .. |
| .o+.Eo. |
+----[SHA256]-----+
[email protected] MINGW64 ~/.ssh
$ ssh -v [email protected]
OpenSSH_7.7p1, OpenSSL 1.0.2p 14 Aug 2018
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to github.com [192.30.253.112] port 22.
debug1: Connection established.
debug1: identity file /c/Users/Administrator/.ssh/id_rsa type 0
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Administrator/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Administrator/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Administrator/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Administrator/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Administrator/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Administrator/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Administrator/.ssh/id_ed25519-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Administrator/.ssh/id_xmss type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Administrator/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.7
debug1: Remote protocol version 2.0, remote software version libssh_0.7.0
debug1: no match: libssh_0.7.0
debug1: Authenticating to github.com:22 as 'git'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: [email protected]
debug1: kex: host key algorithm: ssh-rsa
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ssh-rsa SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in /c/Users/Administrator/.ssh/known_hosts:1
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: RSA SHA256:iZUsywqMgejyYPSY18L+z+dgNOARCIlrU68szXjO294 /c/Users/Administrator/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Trying private key: /c/Users/Administrator/.ssh/id_dsa
debug1: Trying private key: /c/Users/Administrator/.ssh/id_ecdsa
debug1: Trying private key: /c/Users/Administrator/.ssh/id_ed25519
debug1: Trying private key: /c/Users/Administrator/.ssh/id_xmss
debug1: No more authentication methods to try.
[email protected]: Permission denied (publickey).
# 提示沒有更多的身份驗證方法可以 。[email protected]:許可權被拒絕(publickey)。
[email protected] MINGW64 ~/.ssh
$ ssh-agent -s
SSH_AUTH_SOCK=/tmp/ssh-guCKgDb5ZOAw/agent.8692; export SSH_AUTH_SOCK;
SSH_AGENT_PID=10012; export SSH_AGENT_PID;
echo Agent pid 10012;
[email protected] MINGW64 ~/.ssh
$ ssh-add ~/.ssh/id_rsa
Could not open a connection to your authentication agent.
[email protected] MINGW64 ~/.ssh
$ eval 'ssh-agent -s'
SSH_AUTH_SOCK=/tmp/ssh-KSIwZkC0HS0I/agent.4428; export SSH_AUTH_SOCK;
SSH_AGENT_PID=6372; export SSH_AGENT_PID;
echo Agent pid 6372;
[email protected] MINGW64 ~/.ssh
$ ssh-add ~/.ssh/id_rsa
Could not open a connection to your authentication agent.
#出現這個錯
[email protected] MINGW64 ~/.ssh
$ ssh-agent bash
[email protected] MINGW64 ~/.ssh
$ ssh-add ~/.ssh/id_rsa
Identity added: /c/Users/Administrator/.ssh/id_rsa (/c/Users/Administrator/.ssh/id_rsa)
#一些ssh key檔案路徑的資訊
[email protected] MINGW64 ~/.ssh
$ ls`在這裡插入程式碼片`
id_rsa id_rsa.pub known_hosts
[email protected] MINGW64 ~/.ssh
$ vi id_rsa.pub
#此時開啟你剛剛生成的id_rsa.pub,將裡面的內容複製,進入你的github賬號,在settings下,SSH and GPG keys下new SSH key,title隨便取一個名字,然後將id_rsa.pub裡的內容複製到Key中,完成後Add SSH Key。
[email protected] MINGW64 ~/.ssh
$ ssh -T [email protected]
Hi TDYRZ! You've successfully authenticated, but GitHub does not provide shell access.
# 到這問題解決了
你也可以參考這篇部落格 https://www.cnblogs.com/wmr95/p/7852832.html
[email protected] MINGW64 /e/git (master)
$ git log
commit 3eabbe7704d00dbe1c7cf0c016bee98f091ed39d (HEAD -> master)
Author: yuruizai110 <[email protected]>
Date: Tue Oct 9 17:53:23 2018 +0800
add chinese
commit dfcd98877bd972218bf909a46a8931253ad588e1
Author: yuruizai110 <[email protected]>
Date: Tue Oct 9 17:45:27 2018 +0800
add numbers
commit 20e9d44107e9a7bcca3dcc57cceb33ad719213e9
Author: yuruizai110 <[email protected]>
Date: Tue Oct 9 17:39:42 2018 +0800
hellow git
[email protected] MINGW64 /e/git (master)
$ git push -u origin master
To github.com:TDYRZ/yrz.git`
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to '[email protected]:TDYRZ/yrz.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
#你有未提交的更改
[email protected] MINGW64 /e/git (master)
$ git pull --rebase origin master
From github.com:TDYRZ/yrz
* branch master -> FETCH_HEAD
First, rewinding head to replay your work on top of it...
Applying: hellow git
Applying: add numbers
Applying: add chinese
[email protected] MINGW64 /e/git (master)
$ git push -u origin master
Enumerating objects: 10, done.
Counting objects: 100% (10/10), done.
Delta compression using up to 4 threads
Compressing objects: 100% (6/6), done.
Writing objects: 100% (9/9), 863 bytes | 431.00 KiB/s, done.
Total 9 (delta 0), reused 0 (delta 0)
To github.com:TDYRZ/yrz.git
666b724..3bfcc20 master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
五 不扯淡了,看看具體向遠端倉庫上傳自己的專案
- 可以看到我是把本地專案直接放到本地倉庫裡的
- 然後執行add命令將專案新增到索引庫
- 提交到暫存區
- push的時候會報錯,我是採用強推的方法-f,你也可以 先把git的東西fetch到你本地然後merge後再push
六 。從遠端倉庫擋專案
我是直接用的 clone命令
還有許多要學習的,以後會持續跟新