git 使用方法及問題

1.GIT的使用

寫道
git init //創建新倉庫
git add <filename> //倉庫中添加文件
git add * 添加所有未在版本中的文件
git diff <source_branch> <target_branch> //對比版本
git clone /path/to/repositoty //串創建一個本地倉庫的克隆版本
git clone username@host:/path/to/repository //如果是遠程服務器上的倉庫
git fetch origin //返回遠程服務器上面的倉庫
git reset --hard origin/master //獲取當前版本的代碼,本地改動緩存會被清空
git commit -m "代碼提交信息" //提交到本地版本庫中
git push origin master //推送到遠程服務器中
git remote add origin <server> //添加到未克隆的版本服務器上
git checkout -b feature_x //創建一個分支,並切換到該分支上去
git checkout master //切換到主幹上
git branch -d feature_x //刪除分支
git push origin <branch> //推送分支到服務器上
git pull //版本更新
git fetch //獲取
git merge <branch> //合併
git diff <source_branch> <target_branch>
git checkout -- <filename> //替換本地修改的文件

 

 

 

注:

git pull git fetch 的區別

git fetch 只是從服務器上獲取最新的代碼, 而git pull 則是獲取最新代碼後,並與本地代碼的merge合併的結果。相當於執行了以下

git fetch origin master:tmp
git diff tmp 
git merge tmp

 

 2.git 生成key文件及設置

一 、

設置Git的user name和email:

$ git config --global user.name "xuhaiyan"
$ git config --global user.email "[email protected]"

 

二、生成SSH密鑰過程:
1.查看是否已經有了ssh密鑰:cd ~/.ssh
如果沒有密鑰則不會有此文件夾,有則備份刪除
2.生存密鑰:

$ ssh-keygen -t rsa -C “haiyan.xu.vip@gmail.com”
按3個回車,密碼爲空。


Your identification has been saved in /home/tekkub/.ssh/id_rsa.
Your public key has been saved in /home/tekkub/.ssh/id_rsa.pub.
The key fingerprint is:
………………

 

最後得到了兩個文件:id_rsa和id_rsa.pub


3.添加密鑰到ssh:ssh-add 文件名
需要之前輸入密碼。
4.在github上添加ssh密鑰,這要添加的是“id_rsa.pub”裏面的公鑰。

打開https://github.com/ ,登陸xuhaiyan825,然後添加ssh。

5.測試:ssh [email protected]

The authenticity of host ‘github.com (207.97.227.239)’ can’t be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘github.com,207.97.227.239′ (RSA) to the list of known hosts.
ERROR: Hi tekkub! You’ve successfully authenticated, but GitHub does not provide shell access
Connection to github.com closed.

多客戶端配置

http://my.oschina.net/csensix/blog/184434

http://blog.csdn.net/hustpzb/article/details/8230454/

 

3.GIT權限設置

http://blog.csdn.net/mcgrady_tracy/article/details/40658251

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章