【ZZ】Git安裝與配置

3配置
 1.生成keygen 
 
ssh-keygen -t rsa -C "email@email.com"
而後複製~/.ssh/id_rsa.pub的內容至github公鑰,添加新的公鑰,標題任意,公鑰的內容爲id_rsa.pub的內容
 2.爲當前版本庫添加用戶信息 


git config --global user.name "7color"
git config --global user.email email@email.com

3.建立版本庫目錄 

mkdir 7color.github.com
 

4.切換至版本庫目錄 html

cd 7color.github.com

5.初始化版本庫


git init

6.新建文件README
touch README
 
7.將文件提交到 git索引(空格分隔文件名, add . 提交全部)
git add README
 
8.提交版本庫,並添加備註(-m 添加備註,無參數 調用系統編輯器添加備註,-a 省略add,一次性提交索引與提交版本庫,--amend 調整以前的commit)

git commit -m "first commit"
git show #顯示最後一次commit修改的內容
 

9.建立遠程主機的標記7color python

git remote add 7color(origin) git@github.com:xixer/7color.github.com.git
 

10.從7color標記(指定)的remote(遠程主機)獲取最新的版本到本地,並自動進行merge到本地當前分支上(fetch+merge) linux

git pull 7color master

11.提交本地master分支的全部的修改至7color標記(指向)的remote(遠程主機)的master分支 
git push 7color master
 
其它命令
查看版本庫狀態: git status
查看版本紀錄(-p 查看每一個版本的改動紀錄): git log
查看自上次提交以來發生什麼改動: git diff
爲某一版本建立版本標籤: git tag (版本標籤存儲在.git/refs/tags/目錄)
回溯到歷史版本(--soft 回溯到已提交到索引但未提交到版本庫的狀態,--hard 將文件內容也一同回溯,--mixed 默認選項): git reset
git reset 回溯到git add以前的狀態
git reset --soft回溯到git add以後的狀態
分支:
git branch 查看分支(-a 查看全部分支)
git branch 分支名稱 新建分支
git checkout 切換到指定分支(-b 建立分支並切換分支)
git checkout 文件名 恢復某個已修改的文件#撤消未提交的修改
git branch -D 分支名稱 刪除分支(-D強行刪除分支;-d只有分支內容被合併後才能刪除)
git merge 分支名稱 合併指定分支到當前分支
git push git@github.com:ACCOUNT/SPACE.git :heads/BRANCH 刪除遠程分支
還原已提交的修改
git revert HEAD 還原最近一次提交的修改
git revert commit-id 還原指定版本的修改
建立一個鏡像版本庫:
git clone 原始版本庫路徑 鏡像版本庫路徑(local)
git fetch origin 更新 origin 分支。若是 origin 分支不是最新的原始版本庫,會產生錯誤的補丁文件(不會自動merge,僅下載 & 更新索引)
git rebase origin 將工做遷移到最新原始版本庫基礎上
git pull 從協做者那裏獲取更新, 並自動merge到本地的當前分支上(fetch+merge)
echo "test">.gitignore 增長到忽略列表
查看幫助 git help gitignore,幫助在線文檔: 安裝目錄/doc/git/html/gitignore.html
刪除當前文件夾中的版本庫(刪除.git目錄便可): rm -rf .git
git init 初始化後,會在.git/目錄下建立一個版本庫,其中.git/config爲配置文件
使用全局用戶信息,在~/.gitconfig中寫入:
 
[user]
name = 7color
email = email@email.com
*或者*
git config --global user.name "7color"
git config --global user.email email@email.com



錯誤描述
"remote:error: refushing to delete the current branch:refs/heads/BRANCH to git@github.com:ACCOUNT/SPACE.git ![remote rejected] BRANCH (deletion of the current branch prohibited) error: failed to push some refs to 'git@github.com:ACCOUNT/SPACE.git'"
解決方法: 在github.com的管理員頁面,切換當前分支,再次運行刪除分支命令便可.
 
"Permission denied to SPACE.git denied to ACCOUNT"
 
解決方法: 
ssh-keygen -t rsa -C "email@email.com" 
複製~/.ssh/id_rsa.pub內容 
打開githu.com->帳戶設置->SSH公鑰->添加新的公鑰,保存 
ssh-add 完



"FATAL ERROR: Disconnected: No supported authentication methods available.fatal: The remote end hung up unexpectedly."
解決方法: 
ssh -v git@github.com,若是出現successfully authenticated即表示公鑰配置成功. 
若是你同時安裝了Git & TortoiseGit,可使用echo $GIT_SSH查看ssh鏈接方式.
使用其中一種方式,declare GIT_SSH="D:\Git\bin\sh.exe",再次echo $GIT_SSH查看是否修改爲功.接着再次push試試,應該就能夠了.
若是想一勞永逸的作法是個人電腦->高級->環境變量中添加/修改GIT_SSH的值.而後重啓電腦.

支持Git & TortoiseGit 共存
解決方法: 使用puttygen.exe生成的private key複製到github.com的共鑰中便可. 
"To git@github.com:7color/7color.github.com.git ! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:7color/7color.github.com.git'
To prevent you from losing history, non-fast-forward updates were rejected Merge the remote changes (e.g. 'git pull') before pushing again.

See the 'Note about fast-forwards' section of 'git push --help' for details."
解決方法: 
git pull 7color master 
編輯衝突 
git commit -am "resolve conflict" 
git push 7color master 完

資源連接
http://v.youku.com/v_playlist/f5227985o1p0.html 視頻 
http://wangcongming.info/category/geek-tweak/ git-系列(推薦) 
http://roclinux.cn/?p=2115#more-2115 看日記學git 
http://wenku.baidu.com/search?word=git&lm=0&od=0 百度文庫 
http://git-scm.com/ 
http://hi.baidu.com/felixwang/blog/item/7ce2cf1b2fccf7fdaf51338b.html 使用public/private key讓putty(ssh)自動登陸 
http://www.kudelabs.com/2008/09/24/mysmgit-%E4%B9%8Bgit-on-windows%E5%BF%AB%E9%80%9F%E4%B8%8A%E6%89%8B mysmGit 之Git on Windows快速上手 
http://www.ha97.com/book/OpenSource_Guide/ch28s05.html git命令入門 
http://help.github.com/msysgit-key-setup/ ssh keygen 
http://pages.github.com/ git pages 
http://eshilin.blog.163.com/blog/static/13288033020106610250138/ Git startup 
http://eshilin.blog.163.com/blog/static/132880330201066102650433/ Git branch 
http://eshilin.blog.163.com/blog/static/132880330201062991718683/ Git hook book 
http://rongjih.blog.163.com/blog/static/335744612010619111042465/ TortoiseGit密鑰的配置
相關文章
相關標籤/搜索