windows下git常用命令
git官網下載:https://git-scm.com/downloads
tortoisegit下載:https://tortoisegit.org/download/
全局用戶名、郵箱和默認commit提交配置,默認覆蓋原用戶名和郵箱,取消操作 --unset 添加操作 --add
$ git config --global --add user.name "test"
$ git config --global --add user.email "test@example.com"
$ git config --global push.default simple
單個項目配置
$ git config user.name "test"
$ git config user.email "test@example.com"
文本編輯器
$ git config --global core.editor emacs
差異分析工具
$ git config --global merge.tool vimdiff
查看配置信息
$ git config --list
查看幫助
$ git config --help
查看自帶的版本
$ git --version
Git配置SSH秘鑰
右鍵打開Git Bash here,進入.ssh文件夾
$ cd ~/.ssh/
如果提示 “ No such file or directory”,你可以手動的創建一個.ssh文件夾即可
$ mkdir ~/.ssh
生成key
$ ssh-keygen -t rsa -C "test@example.com"
連續按三次回車,這里設置的密碼就為空了,並且創建了key最后得到了兩個文件:id_rsa和id_rsa.pub
進入.ssh文件夾,用記事本打開id_rsa.pub,復制里面的內容添加到github或者bitbucket ssh設置里即可
測試是否添加成功
$ ssh -T git@testgit.org
$ ssh git@github.com
mkdir ~/.ssh
cd ~/.ssh
git config --global --add user.name "zengsm"
git config --global --add user.email "645817606@qq.com"
git config --global --unset user.name zengsm
git config --global --unset user.email 645817606@qq.com
git config --list
ssh-keygen -t rsa -C "645817606@qq.com"
cat ~/.ssh/id_rsa_github.pub
ssh -t git@github.comssh-keygen -t rsa -C "645817606@qq.com"
ssh -t git@github.com
cat id_rsa_github.pub
基本操作
克隆倉庫
$ git clone url
將文件添加到緩存,git add是添加所以文件
$ git add [filename]
查看項目的當前狀態
$ git status -s
顯示已寫入緩存與已修改但尚未寫入緩存的改動的區別
$ git diff [--cached/HEAD/--stat]
將快照的內容寫入緩存區,a直接提交,m是添加注釋
$ git commit [-a/m]
撤銷已緩存的內容
$ git reset HEAD
將條目從緩存區中移除,默認是將文件從緩存區和你的硬盤中刪除
$ git rm [--cached]
Git分支管理
創建分支命令
$ git branch (branchname)
切換分支命令
$ git checkout (branchname)
合並分支命令
$ git merge
列出分支基本命令
$ git branch
刪除分支命令
$ git branch -d (branchname)
stash命令
$ git stash save "feature" 儲藏修改內容
$ git stash apply 應用第一個儲藏
$ git stash list [--stat] 查看保存的儲藏
$ git stash show stashname 顯示一個stash內容
$ git stash show --patch 顯示文件差異
$ git stash drop 刪除最近的一個
$ git stash clear 刪除所有的
FAQ
windows右鍵clone代碼時,提示輸入用戶名和密碼
重新配置一下ssh密碼,$ ssh-keygen -t rsa -C "test@example.com"
windows右鍵clone代碼時,提示輸入密碼
檢查settings設置里面Network選項SSH,將其設置為ssh.exe
Git忽略大小寫時,設置不忽略字符大小寫
git config --system core.ignorecase false
git右鍵settings中Network配置郵件,SSH秘鑰客戶端
git右鍵settings中Diff Viewer配置比較工具, General中配置右鍵顯示項。
Git命令大全
備注:
作者:Shengming Zeng
博客:http://www.cnblogs.com/zengming/
本文是原創,歡迎大家轉載;但轉載時必須注明文章來源,且在文章開頭明顯處給明鏈接。
<歡迎有不同想法或見解的同學一起探討,共同進步>