創(chuàng)建本地倉庫
gitinit
獲取遠程倉庫
gitclone[url]例:gitclonehttps://github.com/you/yourpro.git
創(chuàng)建遠程倉庫
// 添加一個新的 remote 遠程倉庫git remoteadd[remote-name] [url]例:git remoteaddorigin https://github.com/you/yourpro.gitorigin:相當于該遠程倉庫的別名// 列出所有 remote 的別名git remote// 列出所有 remote 的 urlgit remote -v// 刪除一個 renotegit remote rm [name]// 重命名 remotegit remote rename [old-name] [new-name]
從本地倉庫中刪除
gitrmfile.txt// 從版本庫中移除,刪除文件gitrmfile.txt -cached// 從版本庫中移除,不刪除原始文件gitrm-r xxx// 從版本庫中刪除指定文件夾
從本地倉庫中添加新的文件
gitadd.// 添加所有文件gitaddfile.txt// 添加指定文件
提交,把緩存內容提交到 HEAD 里
gitcommit-m"注釋"
撤銷
// 撤銷最近的一個提交.git revert HEAD// 取消commit+addgitreset--mixed// 取消commitgitreset--soft// 取消commit+add+localworkinggitreset--hard
把本地提交 push 到遠程服務器
gitpush[remote-name][loca-branch]:[remote-branch]例:gitpushoriginmaster:master
查看狀態(tài)
gitstatus
從遠程庫中下載新的改動
git fetch[remote-name]/[branch]
合并下載的改動到分支
git merge[remote-name]/[branch]
從遠程庫中下載新的改動
pull = fetch +mergegit pull [remote-name] [branch]例:git pull originmaster
分支
// 列出分支gitbranch// 創(chuàng)建一個新的分支gitbranch(branch-name)// 刪除一個分支gitbranch-d (branch-nam)// 刪除 remote 的分支gitpush(remote-name) :(remote-branch)
切換分支
// 切換到一個分支git checkout[branch-name]// 創(chuàng)建并切換到該分支git checkout -b[branch-name]
##與github建立ssh通信,讓Git操作免去輸入密碼的繁瑣。
首先呢,我們先建立ssh密匙。
ssh key must begin with 'ssh-ed25519', 'ssh-rsa', 'ssh-dss', 'ecdsa-sha2-nistp256', 'ecdsa-sha2-nistp384', or 'ecdsa-sha2-nistp521'. -- from github
根據以上文段我們可以知道github所支持的ssh密匙類型,這里我們創(chuàng)建ssh-rsa密匙。在command line 中輸入以下指令:``ssh-keygen-t rsa``去創(chuàng)建一個ssh-rsa密匙。如果你并不需要為你的密匙創(chuàng)建密碼和修改名字,那么就一路回車就OK,如果你需要,請您自行Google翻譯,因為只是英文問題。
$ ssh-keygen -t rsa Generating public/private rsa key pair.//您可以根據括號中的路徑來判斷你的.ssh文件放在了什么地方Enter file in which to save the key (/c/Users/Liang Guan Quan/.ssh/id_rsa):
到https://github.com/settings/keys這個地址中去添加一個新的SSH key,然后把你的xx.pub文件下的內容文本都復制到Key文本域中,然后就可以提交了。
添加完成之后 我們用ssh git@github.com命令來連通一下github,如果你在response里面看到了你github賬號名,那么就說明配置成功了。let's enjoy github
gitignore
在本地倉庫根目錄創(chuàng)建 .gitignore 文件。Win7 下不能直接創(chuàng)建,可以創(chuàng)建 ".gitignore." 文件,后面的標點自動被忽略;
/.idea? ? ? ? ? // 過濾指定文件夾
/fd/*? ? ? ? ? // 忽略根目錄下的 /fd/ 目錄的全部內容;
*.iml? ? ? ? ? // 過濾指定的所有文件
!.gitignore? ? // 不忽略該文件