一器净、Git配置
1./etc/gitconfig 文件:系統(tǒng)中對所有用戶都普遍適用的配置问慎。若使用 git config 時用 --system 選項萍摊,讀寫的就是這個文件
$ git config --system user.name "runoob"
$ git config --system user.email test@runoob.com
2.~/.gitconfig 文件:用戶目錄下的配置文件只適用于該用戶。若使用 git config 時用 --global 選項如叼,讀寫的就是這個文件
$ git config --global user.name "runoob"
$ git config --global user.email test@runoob.com
3.當(dāng)前項目的 Git 目錄中的配置文件(也就是工作目錄中的 .git/config 文件):這里的配置僅僅針對當(dāng)前項目有效冰木。每一個級別的配置都會覆蓋上層的相同配置,所以 .git/config 里的配置會覆蓋 /etc/gitconfig 中的同名變量
$ git config user.name "runoob"
$ git config user.email test@runoob.com
4.配置文本編輯器 設(shè)置Git默認使用的文本編輯器, 一般可能會是 Vi 或者 Vim笼恰。如果你有其他偏好踊沸,比如 Emacs 的話,可以重新設(shè)置:
$ git config --global core.editor emacs
5.差異分析工具 Git 可以理解 kdiff3社证,tkdiff逼龟,meld,xxdiff追葡,emerge腺律,vimdiff奕短,gvimdiff,ecmerge匀钧,和 opendiff 等合并工具的輸出信息
$ git config --global merge.tool vimdiff
6.查看配置信息
$ git config --list
二翎碑、創(chuàng)建倉庫
$ git init
三、添加文件到暫存區(qū)(index)
$ git add .
$ git add [file_name1] [file_name2]
四之斯、刪除文件
$ git rm
五日杈、克隆遠程倉庫
$ git clone [url]
六、查看狀態(tài)
$ git stauts [-s/-v/-b]
七佑刷、查看修改的詳細信息
$ git diff ## 尚未緩存的改動
$ git diff --cached ## 查看已緩存的改動
$ git diff HEAD ## 查看已緩存的與未緩存的所有改動
$ git diff --stat ## 顯示摘要而非整個 diff
八莉擒、緩存區(qū)內(nèi)容添加到倉庫中
$ git commit -am 'message'
$ git commit -a
$ git commit -m 'message'
追加修改 (這種方式可以修改commit,而不是通過新的commit來修正前一個錯誤的commit)
$ git commit --amend -m 'message'
九瘫絮、回退命令:
$ git reset --hard HEAD^ ## 回退到上個版本
$ git reset --hard HEAD~3 ## 回退到前3次提交之前涨冀,以此類推,回退到n次提交之前
$ git reset --hard commit_id ## 退到/進到 指定commit的sha碼
十檀何、強推到遠程: (回退遠程倉庫分支)
$ git push origin HEAD --force
十一、取消已緩存的內(nèi)容
$ git reset HEAD [-- file]
十二廷支、刪除文件
$ git rm <file> ## 從已跟蹤文件清單中移除
$ git rm -f <file> ## 刪除之前修改過并且已經(jīng)放到暫存區(qū)域
$ git rm --cached <file> ## 從暫存區(qū)域移除频鉴,但仍然希望保留在當(dāng)前工作目錄中
十三、移動或重命名一個文件恋拍、目錄垛孔、軟連接
$ git mv [old_file_name] [new_file_name]
十四、創(chuàng)建分支
$ git branch [branch_name]
十五施敢、切換分支
$ git checkout [branchname]
$ git checkout -b [branchname] ## 切換并創(chuàng)建分支
十六周荐、合并分支
$ git merge
十七、列出分支
$ git branch ## 列出本地分支
$ git branch -a ## 列出本地分支和遠程分支
$ git branch -vv
十八僵娃、刪除分支
$ git branch -d [branch_name] ## 刪除本地分支
$ git branch -D [branch_name] ## 強行刪除本地分支
$ git branch -r -D origin/BranchName ## 刪除本地遠程分支
$ git push origin :br(origin 后面有空格) ## 刪除遠程分支
$ git push origin -d [branchName] ## 刪除遠程分支
十九概作、查看提交歷史
$ git log
$ git log --oneline ## 查看歷史記錄的簡潔的版本
$ git log --oneline --graph ## 查看歷史中什么時候出現(xiàn)了分支、合并
$ git log --reverse --oneline ## 來逆向顯示所有日志
$ git reflog ## 查看所有記錄(包括reset的和未reset的)
二十默怨、標(biāo)簽
$ git tag [tagname] ## 創(chuàng)建一個標(biāo)簽
$ git tag -a [tagname] ## 創(chuàng)建一個帶注解的標(biāo)簽
$ git tag -a [tagname] [commit-id] ## 已提交的追加一個標(biāo)簽
$ git tag ## 查看所有標(biāo)簽
$ git tag -a [tagname] -m "runoob.com" ## 標(biāo)簽指定標(biāo)簽信息
$ git tag -s [tagname] -m "runoob.com" ## 標(biāo)簽PGP簽名標(biāo)簽
$ git push origin [tagname] ## 推送一個本地標(biāo)簽到遠程
$ git push origin --tags ## 推送全部未推送過的本地標(biāo)簽
$ git tag -d [tagname] ## 刪除一個本地標(biāo)簽
$ git push origin :refs/tags/[tagname] ## 刪除一個遠程標(biāo)簽
二十一讯榕、撤銷修改
$ git checkout -- [file_name]
二十二、添加遠程庫
$ git remote add origin [url]
二十三匙睹、查看遠程庫信息
$ git remote -v
二十四愚屁、在本地創(chuàng)建和遠程分支對應(yīng)的分支
$ git checkout -b branchname origin/branchname
二十五、建立本地分支和遠程分支的關(guān)聯(lián)
$ git branch --set-upstream branchname origin/branchname
二十六痕檬、生成SSHkey
$ ssh-keygen -t rsa -C "youremail@example.com"
二十七霎槐、提取遠程倉庫
1、從遠程倉庫下載新分支與數(shù)據(jù):
$ git fetch [alias]
$ git fetch -p
2梦谜、從遠端倉庫提取數(shù)據(jù)并嘗試合并到當(dāng)前分支:
$ git merge [alias]/[branch]
二十八丘跌、推送到遠程倉庫
$ git push [alias] [branch]
二十九袭景、從遠程倉庫拉取代碼
$ git pull [alias] [branch]
三十、將本地未提交的代碼作用到拉取的代碼中
$ git pull --rebase
三十一碍岔、刪除遠程倉庫
$ git remote rm [alias]
三十二浴讯、儲藏
$ git stash
查看儲藏列表
$ git stash list
恢復(fù)到儲藏之前
$ git stash apply
刪除儲藏版本
$ git stash drop
恢復(fù)并刪除
$ git stash pop
三十三、追溯一個文件的歷史修改記錄
$ git blame 文件路徑/文件名
三十四蔼啦、忽略特殊文件
https://github.com/github/gitignore
三十五榆纽、查看修改日志
$ git reflog