git指令-個人整理

  1. 查看用戶名和郵箱地址
$ git config user.name
$ git config user.email
  1. 修改用戶名和郵箱地址
$ git config --global user.name "username"
$ git config --global user.email "email"
  1. 查看文件的內容
$ cat <filename>

4.創建和跳轉文件夾

$ mkdir <filename>
$ cd <filename>

5.顯示當前目錄

$ pwd

6.顯示當前目錄下的文件

$ ls

7.創建版本庫 -->把當前目錄變成git管理的倉庫

$ git init

8.文件增加到暫存區和提交修改

$ git add <filename>
$ git commit -m "commit explaination"

9.查看當前倉庫狀態

$ git status

10.查看差異(修改差異)

$ git diff <filename>
$ git diff HEAD --<filename>查看當前工作區文件與版本庫里面的差異

11.撤銷修改或者撤銷誤刪

  • 撤銷修改:將工作區的修改撤銷,無論這時候文件是進入到暫存區或者在工作區中
  • 撤銷誤刪:將版本庫里面的最近一次文件提取出來
$ git checkout --<filename>

12.撤銷修改

  • 將進入到暫存區里面的修改退回到工作區里面
$ git reset HEAD <filename>

13.刪除文件
工作區中刪除文件 跟右鍵del一樣

$ rm <filename>

版本庫中刪除 之后再提交git commit

$ git rm <filename>

14.關聯遠程數據庫
在github創建庫之后,自動會生成一個關聯地址

$ 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.分支
創建分支

$ git branch <branch-name>

切換分支

$ git checkout <branch-name>

創建并切換

$ 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.查看隱藏區“stash”

$ git stash
$ git stash list

24.取出隱藏區的分支
恢復現場,恢復后stash內容不刪除,需要用到git stash drop

$ git stash apply

恢復現場,同時把stash的內容刪除

$ git stash pop
  1. 強行刪除沒有合并過的分支
$ git git branch -D <branch-name>

26.將遠程最新的提交抓下來

$ git pull

27.建立本地分支與遠程分支的關聯

$ git branch --set-upstream branch-name origin/branch-name

28.創建本地和遠程分支對應的分支

$ git checkout -b branch-name origin/branch-name

29.標簽
創建標簽

$ git tag <tagname>

為當前所在分支創建標簽名字 也可以指定commit-id -->git tag <name> commit-id
創建標簽并加上說明

$ 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>
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • git常用命令 GIT常用命令備忘:http://stormzhang.com/git/2014/01/27/gi...
    新篇章閱讀 8,648評論 1 26
  • 1.git的安裝 1.1 在Windows上安裝Git msysgit是Windows版的Git,從https:/...
    落魂灬閱讀 12,717評論 4 54
  • 大衛綜合癥:到意大利佛羅倫薩后,心思細密、富有創意的游客,在觀賞過包括大衛像的美麗藝術品后,易冒汗、抖震和暈眩,嚴...
    coco_dddd閱讀 450評論 0 0
  • 2017.5.15 本以為事情到此就該結束了。 迷迷糊糊中我竟然睡著了,或許是剛剛的神經太緊繃了。 等我睜開眼,只...
    瘋小蝦閱讀 193評論 3 2