SyntaxHighlighter
git version # 查看版本git config -l # 查看當前配置git config --global user.name "Dean" # 設置用戶名,郵箱 git config --global user.email g.xiangyu1990@gmail.com # 設置用戶名,郵箱 git config --global alias.ci commit # 設置git命令的別名git config --global alias.co checkout # 設置git命令的別名
git倉庫(repository):
# 創建一個本地的git倉庫并命名: git init demo# 克隆一個遠程的git倉庫到指定路徑: git clone https://github.com/a396901990/android.git /path/workpsace
git分支(branch):
git branch # 查看分支git remote show origin # 查看所有分支git branch <branchname> # 創建新分支git checkout <branchname> # 切換到分支git checkout -b <new_branch> # 創建并切換到新分支git branch -d <branchname> # 刪除分支(-D強刪) git branch -m <old> <new> # 本地分支重命名
git添加(add):
git add <file> # 將本地指定文件名或目錄(新增和修改,沒有刪除)的文件添加到暫存區git add . # 將本地所有的(新增和修改,沒有刪除)文件添加到暫存區git add -u # 將本地的(修改和刪除,沒有新增)文件添加到暫存區git add -A # 將本地所有改動添加到暫存區(git add -A = git add . + git add -u)git add -i # 打開一個交互式界面按需求添加文件
git刪除/重命名(rm/mv):
git rm <file> # 刪除文件git rm -r <floder> # 刪除文件夾git rm --cached <file> # 從版本庫中刪除文件,但不刪除文件 git mv <old_name> <new_name> # 文件重命名
git提交(commit):
git commit -m "comment" # 提交暫存區中的內容(已經add)并添加注釋git commit -a # 把修改的文件添加到暫存區(不包括新建(untracked)的文件),然后提交。git commit --amend # 修改提交的commit(沒有push)git commit --amend -m "comment" # 修改commit注解
git差異(diff):
git diff # 查看工作目錄(working tree)暫存區(index)的差別git diff --cached # 查看暫存起來的文件(stage)與并未提交(commit)的差別git diff --staged # 同上git diff HEAD # 查看最后一次提交之后的的差別(HEAD代表最近一次commit的信息)git diff --stat # 查看顯示簡略結果(文件列表)git diff commit1 commit2 # 對比兩次提交的內容(也可以是branch,哈希值)
git查看歷史(log):
git loggit log -3 # 查看前3次修改git log --oneline # 一行顯示一條loggit log -p # 查看詳細修改內容 git log --stat # 查看提交統計信息git log --graph # 顯示何時出現了分支和合并等信息
git查看狀態(status):
git status # 查看你的代碼在緩存與當前工作目錄的狀態git status -s # 將結果以簡短的形式輸出git status --ignored # 顯示被忽略的文件
git存儲(stash):
git stash # 保存當前的工作進度git stash save "message" # 保存進度加說明git stash list # 顯示進度列表git stash pop # 恢復最新保存的工作進度,并將恢復的工作進度從存儲的列表中刪除git stash apply # 恢復最新保存工作進度,但不刪除git stash drop # 刪除一個進度,默認刪除最新的git stash clear # 刪除所有
新聞熱點
疑難解答