Git命令收集

便签笔记

  • git add -A 和 git add . 的区别

    • git add -A 提交所有变化
    • git add -u 提交被修改(modified)和被删除(deleted)文件,不包括新文件(new)
    • git add . 提交新文件(new)和被修改(modified)文件,不包括被删除(deleted)文件
  • 本地分支和远程分支没有关联

    • git branch --track origin/dev dev
  • git 忽略已跟踪文件的修改

    • git update-index --assume-unchanged /path/to/file #忽略跟踪
    • git update-index --no-assume-unchanged /path/to/file #恢复跟踪
    • git ls-files -v | grep '^h' # 查看被标记为 --assume-unchanged 的文件列表
  • git clean 和 git reset --hard 结合使用

    • clean 影响没有被 track 过的文件(清除未被 add 或被 commit 的本地修改)
    • reset 影响被 track 过的文件 (回退到上一个 commit)
    • n :显示将要被删除的文件
    • d :删除未被添加到 git 路径中的文件(将 .gitignore 文件标记的文件全部删除)
    • f :强制运行
    • x :删除没有被 track 的文件
  • 覆盖追加提交

    • git commit --amend
  • 查看本地分支和远程分支的跟踪关系

    • git branch -vv
  • 比较分支差异

    • git diff branch1 branch2 --stat
    • git diff branch1 branch2
  • git查看commit提交的内容

    • git show --raw commitid
    • git show commitid
  • git拉取远程分支到本地

    • git checkout -b local_branch_name origin/origin_branch_name
  • git 删除本地分支

    • git branch -d local_branch_name
  • git 重命名分支

    • git branch -m hotfix/1.3.4
    • git push --delete origin oldBranch
    • git push -u origin newBranch
  • 当合并分支时遇到错误或者冲突,取消这次合并

    • git merge --abort
  • 提交后发现忘记了暂存某些需要的修改,可以像下面这样操作

    git commit -m 'initial commit'
    git add forgotten_file
    git commit --amend
    
  • 标签管理

    • git tag //列出标签
    • git tag -a v1.4 -m "my version 1.4" //附注标签的创建
    • git tag -a v1.2 //给最新一次提交打上标签
    • git tag -a v1.2 9fceb02 //后期打标签
    • git tag -d v1.4-lw //删除标签
    • git tag -l | xargs git tag -d //删除标签
    • git push origin --delete tagname //移除远程仓库标签
    • git push origin :refs/tags/标签名 //移除远程仓库标签(推荐:避免分支和标签同名,造成分支误删)
    • git push origin v1.5 //推动单个标签
    • git push origin --tags //推送很多标签
    • git tag -n --sort=-taggerdate | head -n 2 //git 获取最新的tags标签最简单方法1
    • git describe --abbrev=0 //获取最新的tag
    • git describe --tags git rev-list --tags --max-count=1 // 获取最新的tag
  • git flow

    • git flow feature start MYFEATURE //建了一个新的 feature 分支,并切换到该分支
    • git flow feature finish MYFEATURE //完成开发新特性(合并到develop,删除分支,切换回develop分支)
    • git flow feature publish MYFEATURE //发布新特性分支到远程服务器
    • git flow feature pull origin MYFEATURE //取得一个发布的新特性分支
    • git flow feature track MYFEATURE //追溯远端上的特性
    • git flow hotfix start VERSION [BASENAME] //
    • git flow hotfix finish 1.3.4 //(合并到master分支,创建标签1.3.4,合并到develop分支,删除本地hotfix/1.3.4分支)
  • git stash

    • git stash apply //reapply the changes
    • git stash -u //also include changes to untracked files
    • git stash -a //also include changes to ignored files
    • git stash list //stash list
    • git stash save "message" //stash with a description
    • git stash pop stash@{2} //choose which stash to re-apply by passing its identifier
    • git stash show //view stash diffs
    • git stash show -p //view the full diff of a stash
    • git stash -p //choose to stash
    • git stash branch add-stylesheet stash@{1} //create a new branch to apply your stashed changes
    • git stash drop stash@{1} //delete a particular stash
    • git stash clear //delete all stashes
  • git flow feature

      git flow feature start test123123
      git tag -a V.1.0.17.3
      git tag -a V3.1.51.4 89b58b133fef
      maybe need pull request
      git flow feature finish test123123
      git flow release start V2.0.10.0
      git flow release finish V2.0.10.0
      git checkout develop
      git push
      git checkout master
      git push
      git push --tags
    
  • git hotfix

      git flow hotfix start hotfix/jerry112233
      git flow hotfix start V.1.0.17.6
      git tag -a V.1.0.17.6
      git tag -a V3.1.51.4 89b58b133fef
      maybe need pull request
      git flow hotfix finish hotfix/jerry112233
      git checkout develop
      git push
      git push --tags
      git checkout master
      git push
    

相关链接

posted @ 2019-06-05 00:54  绝技小嗨皮  阅读(185)  评论(0编辑  收藏  举报
Title