Git經常使用命令總結

經常使用的git命令

  • git init git 初始化
  • git config --global user.name "xxx" 配置用戶名
  • git config --global user.email "xxx@xxx.com" 配置郵件
  • git add git add . 把全部變化提到暫存區 git add xxx 把制定文件提到暫存區
  • git status 查看當前文件狀態
  • git commit -m "" 提交更新
  • git commit -am 'xxx' 將add和commit合爲一步, 但只能cover到已被track的文件
  • git show commit_id 顯示某個提交的詳細內容
  • git log 查看commit日誌
  • git reset --hard commit_id 回退到某個commit
  • git revert commit_id 進入到某個commit的代碼,並生成新的commit
  • git remote -v 查看本地關聯的遠程倉庫
  • git remote add xxx 地址 關聯遠程倉庫,名字爲xxx
  • git remote rename oldname newname 修改遠程倉庫的名字
  • git remote rm name 刪除名字爲name的遠程倉庫的關聯
  • git pull name branch 拉取名字爲name的遠程倉庫的branch分支
  • git push name branch 推送名字爲name的遠程倉庫的branch分支
  • git checkout -b branch [remote/master] 新建並進入一個名字爲branch的分支 可選參數指在某個分支基礎上新建
  • git checkout branch 切到名字爲branch的分支
  • git branch -D branch 刪除名字爲branch的分支
  • git branch -a 查看全部分支 包括本地和遠程
  • git clone 地址 克隆項目到本地
  • git fetch [name] [branch] 將獲取遠程倉庫的更新取回本地,取回的代碼對本地的開發代碼沒有影響,無參數時默認取全部
  • git merge branch 把branch分支合併到當前分支
  • git push name :branch 刪除名字爲name的遠程的branch分支

    git rebase -i HEAD~xgit rebase -i commi_id (commi_id不參與合併的) 合併多個commit, pick改成s, 若有衝突,解決之後繼續 git add . git rebase --continue 取消合併 git rebase --abortgit

  • git tag name [commit_id] 增長名字爲name的tag, commit_id制定commit處打tag
  • git tag 查看全部tag,按字母排序
  • git tag -d name 刪除名字爲name的tag
  • git push origin tagname 把名字爲tagname的tag推到遠程
  • git push --tags 把全部tag推送到遠程倉庫
  • git push origin :refs/tags/<tagname> 刪除遠程tag
相關文章
相關標籤/搜索