經常使用 Git 命令清單

前言

知識的四大階段,記錄,分享,討論html

經常使用命令

重要數據流:git

  1. 數據流一: Workspace (add) -> Index (commit)-> Respository (push)-> Remote
  2. 數據流二:Remote (fetch/clone) -> Respository (checkout) -> workspace
  3. 數據流三:Remote (pull) -> workspace

名詞解釋:fetch

  1. Workspace : 工做區
  2. Index / Stage : 暫存區
  3. Respository: 倉庫區(或本地倉庫)
  4. Remote: 遠程倉庫

入門

新建代碼庫 和配置

# 新建一個目錄,將其初始化爲Git代碼庫
1. $git init [project-name]:  

# 顯示當前的Git 配置,
# 配置文件爲 .gitconfig
2. $git config --list

增刪提交代碼

# 查看代碼修改狀況
1. $git status

# 添加代碼到暫存區, 全添加
2. $git add . 

# 提交暫存區代碼到倉庫,所有提交,註釋信息
3. $git commit -a -m [message]

# 本地分支推送本地倉庫代碼到與之關聯的遠程倉庫
4. $git push origin

# 本地分支拉取與之關聯的遠程倉庫代碼
5. $git pull origin

# 查看當前分支的版本歷史
6. $git log

# 顯示暫存區和工做區的差別
7. $git diff

進階

分支

# 列出全部分支
1. $git branch

# 新建分支
2. $git branch [branch-name] 

# 新建分支,並切換到該分支
3. $git checkout -b [branch-name]

# 切換到指定分支,並更新工做區
4. $git checkout [branch-name]

# 合併指定分支到當前分支
5. $git merge [branch]

# 刪除分支
6. $git branch -d [branch-name]

# 提交暫存區代碼到倉庫,所有提交,註釋信息
3. $git commit -a -m [message]

標籤

# 列出全部 tag
1. $git tag

# 在當前的 commit 上新建一個 tag 
2. $git tag [tag-name]

# 刪除 tag
6. $git tag -d [tag-name]

遠程同步

# 顯示全部遠程倉庫
1. $git remote -v

# 顯示某個遠程倉庫的信息
2. $git remote show [remote]

# 獲取遠程全部變更
3. $git fetch 

# 獲取指定遠程倉庫的全部變更
3. $git fetch [remote]

撤銷

# 重置暫存區和工做區,與上一次 commit 保持一致
1. $ git reset --hard

# 重置當前分支的HEAD 爲指定commit ,同時重置暫存區和工做區,與指定commit一致
2. $ git reset --hard [commit]

# 融合
3. $git merge [branch]

# 衍合
4. $git rebase [branch]

致謝

http://www.ruanyifeng.com/blog/2015/12/git-cheat-sheet.htmlspa

相關文章
相關標籤/搜索