git簡單入門

  

 

  首先下載安裝git,完成後打開git bash,能夠先輸入:git help 簡單瞭解一下有哪些命令.....html

 

一、配置git,在git bash窗口中輸入下面兩行命令:git

  git config --global user.name "user_name"github

  git config --global uer.email "name@example.com"windows

  紅色文字部分根據我的信息修改(下同)ruby

  --global參數表示當前計算機上將要建立的全部倉庫都使用這個配置。bash

二、建立路徑:mkdir dir_nameapp

三、跳轉到制定目錄:cd dir_namefetch

四、顯示當前工做路徑: pwdui

五、將當前目錄變成git能夠管理的倉庫:git initspa

六、添加並提交修改:

  git add file_name

  git commit -m "added a file"

七、查看狀態:git status

八、查看修改先後的變化:git diff

九、查看提交記錄:

  git log

讓結果只顯示一行的命令

  git log --pretty=oneline

或者先配置

  git config format.pretty oneline

另查看分支圖:

  git log --graph

十、回到過去:

  退回上一版本:git reset --hard head^

  退回上上一版本:git reset --hard head^^

  退回上...(N個)一版本:git reset --hard head~N

十一、回到過去或將來:

(1)獲取歷次commit 的 id 號:git reflog

(2)git reset --hard commit_id

十二、撤銷指定文件的修改(包括刪除):

(1)撤銷在工做區的修改(即讓文件回到最近一次git commitgit add時的狀態):git checkout -- filename

  其中 -- 表示在當前分支下,而不是轉換到新的分支

(2)撤銷在暫存區及工做區的修改(即讓文件回到最近一次git commit時的狀態):git reset head filename

1三、與本地倉庫與GitHub 倉庫的關聯:

  一個簡單的方法:在GitHub上建立新的倉庫後,會跳轉到對應的倉庫。咱們根據 Quick setup 的提示進行操做便可,即將對應的命令行復制、粘貼到git bash窗口上

1四、branch的操做:

(1)建立並跳轉到新的branch:

  git checkout -b branch_name

至關於:

  git branch branch_name

  git checkout branch_name

(2)跳轉到指定branch (包括master):

  git checkout branch_name

(3)將分支推送到遠程倉庫:

  git push origin branch_name

(4)刪除branch:

  已合併分支刪除:git branch -d branch_name   或   git checkout -d branch_name

  未合併分支刪除:git branch -D branch_name   或 git checkout -D branch_name

(5)查看全部分支:

  git branch

1五、更新本地倉庫至最新改動:

  git pull

1六、合併制定分支到當前分支:

  git merge branch_name

加上 --no-ff 參數表示禁用Fast forward,能夠保留分支歷史:

  git merge --no-ff branch_name

若出現衝突,則須要修改文件而後再合併;改完以後執行:

  git add file_name

合併前可先檢查分支的差別:

  git diff source_branch target_branch

1七、獲取遠程倉庫的最新版本並覆蓋本地版本:

  git fetch origin

並將本地主分支指向它:

  git reset --hard origin/master

1八、標籤操做:

(1)建立標籤:git tag v1.0 commit_id

(2)顯示指定標籤版本:git show tag_name

1九、打開圖形化git:

  gitk

 20、工做現場的操做:

(1)保存工做現場:git stash

(2)查看:git stash list

(3)恢復: git stash apply

(4)刪除:git stash drop

(5)恢復並刪除:git stash pop

 

本文地址:http://www.cnblogs.com/laishenghao/p/5500835.html

做者博客:( •̀ ω •́ )y