- 查看用戶名和郵箱地址
$ git config user.name
$ git config user.email
- 修改用戶名和郵箱地址
$ git config --global user.name "username"
$ git config --global user.email "email"
- 查看文件的內容
$ cat <filename>
4.創(chuàng)建和跳轉文件夾
$ mkdir <filename>
$ cd <filename>
5.顯示當前目錄
$ pwd
6.顯示當前目錄下的文件
$ ls
7.創(chuàng)建版本庫 -->把當前目錄變成git管理的倉庫
$ git init
8.文件增加到暫存區(qū)和提交修改
$ git add <filename>
$ git commit -m "commit explaination"
9.查看當前倉庫狀態(tài)
$ git status
10.查看差異(修改差異)
$ git diff <filename>
$ git diff HEAD --<filename>查看當前工作區(qū)文件與版本庫里面的差異
11.撤銷修改或者撤銷誤刪
- 撤銷修改:將工作區(qū)的修改撤銷痢法,無論這時候文件是進入到暫存區(qū)或者在工作區(qū)中
- 撤銷誤刪:將版本庫里面的最近一次文件提取出來
$ git checkout --<filename>
12.撤銷修改
- 將進入到暫存區(qū)里面的修改退回到工作區(qū)里面
$ git reset HEAD <filename>
13.刪除文件
工作區(qū)中刪除文件 跟右鍵del一樣
$ rm <filename>
版本庫中刪除 之后再提交git commit
$ git rm <filename>
14.關聯遠程數據庫
在github創(chuàng)建庫之后妆偏,自動會生成一個關聯地址
$ git remote add origin git@132812:path/repo-name.git
15.推送到遠程庫
$ git push -u origin master
$ git push origin master
$ git push origin <branch-name>
16.查看版本信息
$ git log
$ git log --pretty=online
17.版本回退
一個^指當前版本的上一個版本
$ git reset -hard head^
回退到為commit-id的版本
$ git reset -hard commit-id
18.查看命令歷史 包括各個版本的id
$ git reflog
19.克隆文件
$ git clone git@132812:path/repo-name.git
20.分支
創(chuàng)建分支
$ git branch <branch-name>
切換分支
$ git checkout <branch-name>
創(chuàng)建并切換
$ git checkout -b <branch-name>
查看所有分支
$ git branch
當前分支合并指定分支
$ git merge <branch-name>
刪除分支
$ git branch -d <branch-name>
21.查看合并分支后的情況
$ git log --graph -pretty=online --abbrev-commit
22.合并分支并提交 禁用fast forward
$ git merge --no-ff -m "commit explaination" <branch-name>
23.查看隱藏區(qū)“stash”
$ git stash
$ git stash list
24.取出隱藏區(qū)的分支
恢復現場,恢復后stash內容不刪除,需要用到git stash drop
$ git stash apply
恢復現場,同時把stash的內容刪除
$ git stash pop
- 強行刪除沒有合并過的分支
$ git git branch -D <branch-name>
26.將遠程最新的提交抓下來
$ git pull
27.建立本地分支與遠程分支的關聯
$ git branch --set-upstream branch-name origin/branch-name
28.創(chuàng)建本地和遠程分支對應的分支
$ git checkout -b branch-name origin/branch-name
29.標簽
創(chuàng)建標簽
$ git tag <tagname>
為當前所在分支創(chuàng)建標簽名字 也可以指定commit-id -->git tag <name> commit-id
創(chuàng)建標簽并加上說明
$ git tag -a <tagname> -m "commit explaination"
查看所有標簽
$ git tag
查看標簽信息
$ git show <tagname>
刪除本地tag
$ git tag -d <tagname>
推送某個標簽到遠程
$ git push origin <tagname>
推送所有標簽
$ git push origin --tags
刪除一個遠程標簽
$ git push origin :refs/tags/<tagname>