windows gitlinux
下載連接: Msysgit https://git-scm.com/download/wingit
1 進入git bash進行第一次配置github
git config --global user.name "your name"windows
git config --global user.email "***.com"bash
git config --list 查看配置列表ssh
2 Git 倉庫測試
git init 初始化本地倉庫spa
git add file 添加文件到暫存區 ---》(git reset HEAD file 恢復文件從暫存區到未暫存區,即清楚git add動做) --》(git checkout -- file 刪除修改,discard changes in working directory)指針
git commit -m "log msg" file 提交文件到本地倉庫blog
git status 查看文件狀態
git reset --hard 版本哈希號 (恢復到某個版本)
git rm file (刪除文件)
遠程倉庫
1. 配置SSH keys
登陸 https:/github.com -> Settings -> SSH and GPG keys
1) add New SSH key
2) ssh-keygen -t rsa -C "826423614@qq.com" 生成公鑰 id_rsa.pub
3)ssh -T git@github.com 測試是否鏈接成功
4) 添加遠程倉庫 New repository
echo "# git_study" >> README.md git init git add README.md git commit -m "first commit" git remote add origin https://github.com/Meer6767/git_study.git git push -u origin master
第一次git push可能須要輸入密碼和用戶名,就是登錄github的用戶名密碼
克隆倉庫
git clone https://github.com/Meer6767/git_study.git
git每次pull或push都要輸入用戶名和密碼解決方法
git config --global credential.helper store
這個命令是在本地生成一個帳號密碼文件,這樣就不用每次都輸入了(可是還得輸入一次)
這個指令對於windows,linux都是通用的!!!
能夠經過命令
cat ~/.git-credentials
標籤管理
git checkout tag_name 取得對應tag的代碼
tag是對歷史提交的一個id的引用,若是理解這句話就明白了tag的含義
使用git checkout tag便可切換到指定tag,例如:git checkout v0.1.0
切換到tag歷史記錄 會使當前指針處在分離頭指針狀態,這個時候的修改是很危險的,在切換回主線時若是沒有合併,以前的修改提交基本都會丟失,若是須要修改能夠嘗試git checkout -b branch tag建立一個基於指定tag的分支,例如:git checkout -b test v0.1.0 這個時候就在這個test分支上進行開發,以後能夠切換到主線合併。
注意這時候的test分支的代碼不少都是tag版本處的,可是test分支head節點在最前面,這時候切換到主線進行合併,要注意合併後的代碼衝突問題,不要讓舊代碼覆蓋了主線的新代碼。
git checkout -B
這個命令,能夠強制建立新的分支,爲何加-B呢?若是當前倉庫中,已經存在一個跟你新建分支同名的分支,那麼使用普通的git checkout -b 這個命令,是會報錯的,且同名分支沒法建立。若是使用-B參數,那麼就能夠強制建立新的分支,並會覆蓋掉原來的分支。
git checkout -B test v0.1.0 強制建立一個基於指定的tag的分支。
分支管理
默認有個master分支git branch branch_name 添加新分支 git branch 列出分支git checkout branch_name 切換分支git branch master, git merge branch_name 將分支的代碼合併到master裏git branch -d branch_name 刪除無用的分支