Git實用命令

config

  • 配置用戶名和郵箱
    git config --global user.name "username"
    git config --global user.email "mailbolx@163.com"
  • git配置代理(看ss配置)
    git config --global http.proxy 'socks5://127.0.0.1:1080' git config --global https.proxy 'socks5://127.0.0.1:1080'
  • 取消代理
    git config --global --unset http.proxy
  • git打開顏色開關
    git config --global color.ui true

branch

  • 設置本地dev分支track遠程分支origin/master
    git branch -u origin/master dev
  • 切到上一個工作分子
    git checkout -
  • 查看本地分支track的遠程分支
    git branch -vv
  • checkout遠程分支
    git checkout -t origin/dev //-t參數, 創建和遠程分支一樣名字的本地分支
  • 刪除遠程分支
    git push [遠程名] :[分支名]
    git push origin :serverfix

commit

  • 獲取兩個branch/commit (分支 / 提交) 共同的祖先
    git merge-base commit1 commit2
  • 暫存提交/簽出暫存
    git stash/git stash pop
  • 合并多次提交,生成patch
    git diff HEAD~2..HEAD > my-patch.diff git format-patch HEAD~2..HEAD --stdout > changes.patch git format-patch -x --stdout > patch-ddmmyyy.patch git diff tag1 tag2 > the-patch.diff
  • 查看改變的文件列表
    git diff tag1 tag2 --stat
  • 僅查看指定文件/文件夾改變
    git log -- "some file/dir"
    git diff tag1 tag2 -- some/file/name

tag

  • 在當前位置添加tag
    git tag -a v1.4 -m "v1.4"
  • 為commit添加tag
    git tag -a v1.2 9fceb02
  • 推送tag到遠程分支
    git push origin --tags
    git push origin 標簽名
  • 刪除本地標簽:
    git tag -d 標簽名
  • 刪除遠程標簽:
    git push origin :refs/tags/標簽名

submodule

  • 添加submodule
    git submodule add https://github.com/hexojs/hexo-theme-light.git themes/light git commit -am "add submodule" git submodule init git submodule update
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容