git常用命令

git常用命令:

  • git init //初始化本地git環境
  • git clone XXX//克隆一份代碼到本地倉庫
  • git pull //把遠程庫的代碼更新到工作臺
  • git pull --rebase origin master //強制把遠程庫的代碼跟新到當前分支上面
  • git fetch //把遠程庫的代碼更新到本地庫
  • git add . //把本地的修改加到stage中
  • git commit -m 'comments here' //把stage中的修改提交到本地庫
  • git push //把本地庫的修改提交到遠程庫中
  • git branch -r/-a //查看遠程分支/全部分支
  • git checkout master/branch //切換到某個分支
  • git checkout -b test //新建test分支
  • git checkout -d test //刪除test分支
  • git merge master //假設當前在test分支上面,把master分支上的修改同步到test分支上
  • git merge tool //調用merge工具
  • git stash //把未完成的修改緩存到棧容器中
  • git stash list //查看所有的緩存
  • git stash pop //恢復本地分支到緩存狀態
  • git blame someFile //查看某個文件的每一行的修改記錄()誰在什麼時候修改的)
  • git status //查看當前分支有哪些修改
  • git log //查看當前分支上面的日誌信息
  • git diff //查看當前沒有add的內容
  • git diff --cache //查看已經add但是沒有commit的內容
  • git diff HEAD //上面兩個內容的合併
  • git reset --hard HEAD //撤銷本地修改
  • echo $HOME //查看git config的HOME路徑
  • export $HOME=/c/gitconfig //配置git config的HOME路徑

團隊協作git操作流程:

  • 克隆一個全新的項目,完成新功能並且提交:

  1. git clone XXX //克隆代碼庫
  2. git checkout -b test //新建分支
  3. modify some files //完成修改
  4. git add . //把修改加入stage中
  5. git commit -m '' //提交修改到test分支
  6. review代碼
  7. git checkout master //切換到master分支
  8. git pull //更新代碼
  9. git checkout test //切換到test分支
  10. git meger master //把master分支的代碼merge到test分支
  11. git push origin 分支名//把test分支的代碼push到遠程庫
  • 目前正在test分支上面開發某個功能,但是沒有完成。突然一個緊急的bug需要處理

  1. git add .
  2. git stash
  3. git checkout bugFixBranch
  4. git pull --rebase origin master
  5. fix the bug
  6. git add .
  7. git commit -m ''
  8. git push
  9. git checkout test
  10. git stash pop
  11. continue new feature's development
  • git工作流

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章