[TOC]html
git add
後被即將被提交的文件~/.gitconfiggit
git config --list git config --list --system git config --list --global git config --list --local
git config --list
或者 cat ~/.gitconfig
shell
git config --global user.name 'xxx'
服務器
git config --global user.emall 'xxx'
app
git config --global color.ui true
工具
git config --global alias.co chechout
— 將checkout
設置成co
fetch
初始化git
庫ui
git init
與git init —bare
區別:url
—bare
選項時,就會生成.git
目錄以及其下的版本歷史記錄文件,這些版本歷史記錄文件就存放在.git
目錄下—bare
選項時(俗稱裸庫
),再也不生成.git
目錄,而是隻生成.git
目錄下面的版本歷史記錄文件,這些版本歷史記錄文件也再也不存放在.git
目錄下面,而是直接存放在版本庫的根目錄下面.git clone xxxx
— 默認拉取master
分支spa
git clone -b branchName xxxx
— 拉取指定分支
當你經過一番掙扎終於搞定一個bug,順手提交到 git 服務器,內心一陣暗爽. 這時發現你當前所在的分支是 master !!!這個分支不是開發者用來提交代碼的,惋惜如今剁手也晚了.
git checkout master
—切到主分支git log
— 獲取你提交的版本號git checkout -b dev
—切換到開發分支git cherry-pick [commit id]
git mv [file-oldName][file-newName]
— 更名文件,而且將這個更名放入暫存區git mv [file-oldName_dir][file-newName_dir]
git checkout --[fileName]
— 撤銷某個文件的修改git checkout HEAD -- [fileName]
— 恢復到fileName
最近的一次提交
git add
以後,文件就參加到了暫存區,想丟棄修改分兩步.
git reset HEAD [fileName]
— 從暫存區移除文件git checkout --[fileName]
— 撤銷這個文件的修改這個一直沒用過
http://blog.csdn.net/shichaos...
http://www.jianshu.com/p/253e...
http://www.jianshu.com/p/3622...
https://ithelp.ithome.com.tw/...
git remote set-url origin XXX
git remote add all [url]
git remote set-url --add all [url]
git config branch.master.remote all
注意:: all
是能夠隨意起名字的.
最後push 的時候
git push all master
git add [file1][file2]…
— 添加指定文件到暫存區git add .
— 添加當前的全部文件到暫存區hunk
git add [file_name] -p
使用命令git add -p時,你能夠在每一個改動「塊」(即:連續的改動會被組織到一塊兒)時進行一些選擇,好比:切分當前塊爲更小的塊、跳過一個改動塊、甚至手動的編輯該塊,你能夠敲入?來查看全部該命令提供的選項。
git rm [file_name] --cached
git commit -m '描述信息'
— 提交暫存區到倉庫區git commit -a
— 提交工做區
自上次commit以後的變化,直接到倉庫區
. eg: git commit -a -m 'hello world'
,這個提交不須要使用git add
git commit -v
— 提交時顯示全部diff信息git commit --amend [file1]... -m '描述'
— 向一個commit
裏追加新的改動文件git reset –mixed
此爲默認方式,不帶任何參數的git reset
,即時這種方式,它回退到某個版本,保留修改源碼,回退commit和index信息. 下次提交還須要git add
.
git reset –soft
回退到某個版本,保留修改源碼,回退了commit的信息,不會恢復到index file一級。若是還要提交,直接commit便可(不須要git add
)
git reset –hard
完全回退到某個版本,不保留修改源碼,本地的源碼也會變爲上一個版本的內容
不會出現commit
會有commit
git diff --cached
或者 git diff --staged
— 查看暫存區的改動
git difftool --cached
— 使用工具查看
git push origin branch-name --force
—force 強制推送
推薦:
不實用 Fast-forward
的方式合併
git merge branche1 --no-ff
git mergetool
git rebase --abort
在使用Git 版本控管的過程當中,會產生大量的版本,隨着寒暑易節、物換星移,在這衆多的版本之中,必定會有一些值得咱們紀錄的幾個重要版本,這就是標籤 (Tag) 能幫咱們作的事.
輕量tag是指向提交對象的引用,
附註Tag則是倉庫中的一個獨立對象。建議使用附註Tag。
git stash save(save能夠省略) -u '說明信息'
— 保存到git 棧git stash list
— 列出git棧信息git stash pop
— 取出最近一次保存的內容 git stash apply stash@{1}
— 取出指定的內容git stash drop stash@{1}
— 刪除指定的內容git stash clear
— 清空git 棧git branch
— 列出全部本地分支git branch -r
— 列出全部遠程分支git branch -a
--列出全部本地和遠程分支git branch [branchName]
— 新建一個,並依然停留在當前git checkout -b [branch-name]
— 新建分支,並切換該分支git checkout [branch-name]
— 切換分支git fetch origin branchname:branchname
— 拉取遠程分支到本地git branch -d (-D強制刪除) [branch-name]
— 刪除本地分支git push origin --delete [branch-name]
— 刪除遠程分支git branch -m [old_branch_name] [new_branch_name]
— 重命名分支git branch --merged
— 本地分支裏哪些分支是已經合併進你當前所在的分支git branch --no-merged
— 哪些分支尚未合併進當前所在的分支切換分支注意事項
git stash
保存起來)分支說明
git checkout -b feature-x master
git checkout -b release-1.2 develop
git checkout -b fixbug-X master
git log --pretty=oneline
— 查看commit號git log --oneline -5
git log --oneline -5 --author="zongqi"
git log --oneline -5 --grep="index.html"
git log --oneline -5 --before='2017-07-01'
1 week, 3 days
git log --oneline -5 --before='1 week'
brew install tig
gitk
git gui
此時提交的代碼不能merge master
命令 | 簡要說明 |
---|---|
git add | 添加至暫存區 |
git add–interactive | 交互式添加 |
git apply | 應用補丁 |
git am | 應用郵件格式補丁 |
git annotate | 同義詞,等同於 git blame |
git archive | 文件歸檔打包 |
git bisect | 二分查找 |
git blame | 文件逐行追溯 |
git branch | 分支管理 |
git cat-file | 版本庫對象研究工具 |
git checkout | 檢出到工做區、切換或建立分支 |
git cherry-pick | 提交揀選 |
git citool | 圖形化提交,至關於 git gui 命令 |
git clean | 清除工做區未跟蹤文件 |
git clone | 克隆版本庫 |
git commit | 提交 |
git config | 查詢和修改配置 |
git describe | 經過里程碑直觀地顯示提交ID |
git diff | 差別比較 |
git difftool | 調用圖形化差別比較工具 |
git fetch | 獲取遠程版本庫的提交 |
git format-patch | 建立郵件格式的補丁文件。參見 git am 命令 |
git grep | 文件內容搜索定位工具 |
git gui | 基於Tcl/Tk的圖形化工具,側重提交等操做 |
git help | 幫助 |
git init | 版本庫初始化 |
git init-db* | 同義詞,等同於 git init |
git log | 顯示提交日誌 |
git merge | 分支合併 |
git mergetool | 圖形化衝突解決 |
git mv | 重命名 |
git pull | 拉回遠程版本庫的提交 |
git push | 推送至遠程版本庫 |
git rebase | 分支變基 |
git rebase–interactive | 交互式分支變基 |
git reflog | 分支等引用變動記錄管理 |
git remote | 遠程版本庫管理 |
git repo-config* | 同義詞,等同於 git config |
git reset | 重置改變分支「遊標」指向 |
git rev-parse | 將各類引用表示法轉換爲哈希值等 |
git revert | 反轉提交 |
git rm | 刪除文件 |
git show | 顯示各類類型的對象 |
git stage* | 同義詞,等同於 git add |
git stash | 保存和恢復進度 |
git status | 顯示工做區文件狀態 |
git tag | 里程碑管理 |