• git常用命令


    • 查看所有配置,用户信息和文件位置
    git config --list --show-origin
    
    • 用户信息配置
    git config --global user.name "user_name"
    git config --global user.email "user_email@qq.com"
    
    • 查看远程库
    git remove -v
    
    • 本地库关联远程库
    git remote add orgin xxxx.git
    
    • 删除关联的远程库
    git remote rm origin
    
    • 查看提交日志
    git log --pretty=oneline
    
    • 撤销修改某个文件
    git checkout -- <file_name>
    
    • 删除文件
    git rm <file_name>
    
    • 版本回滚
    git reset --soft|--mixed|--hard  HEAD^ # 回滚到前一个版本
    git reset --soft|--mixed|--hard  HEAD~n # 回滚到前n+1个版本
    git reset --soft|--mixed|--hard <commit_id> # 回滚到对应的commit的版本
    git reflog # 查看git reset的日志,用于恢复git reset
    
    - soft:表示保留源码,只回退到commit信息到某个版本,不涉及暂存区的回退,如果还需要提交,直接commit即可。
    - mixed:表示会保留源码,只是将git commit和暂存区信息回退到了某个版本。
    - hard:会将所有的信息回退到某个版本。
    
    • 线上版本回退,代码已经更新到远程仓库
    git revert <commit_id>
    
    • 创建分支并切换到新分支
    git checkout -b <branch_name>
    
    • 切换分支
    git checkout <branch_name>
    
    • 删除已合并的分支
    git branch -d <branch_name>
    
    • 删除未合并的分支
    git branch -D <branch_name>
    
    • 不使用Fast forward方式合并分支
    git merge --no-ff -m "message" <branch_name>
    
    • 暂存工作区
    git stash
    
    • 查看暂存工作区
    git stash list
    
    • 恢复暂存工作区
    # 第一种方式
    git stash pop 
    
    # 第二种方式
    git stash apply stash@{<id>}
    git stash drop 
    
    • 复制特定提交到当前分支
    git cherry-pick <commit_id> # 常用来将修复的bug分支合并过来,而不是将整个master分支合并过来
    
    • 变基拉取数据
    git pull --rebase # 可以减少合并的一次commit,注意本地目录必须是干净的,如果不干净,需要先commit
    
    • 查看分支
    git branch # 查看本地分支
    git branch -r # 查看远程分支
    git branch -a # 查看所有分支
    git fetch # 远程分支和本地分支同步
    
  • 相关阅读:
    merge into语句的使用
    mybatis框架下解决数据库中表的列的字段名和实体类属性不相同的问题
    Mybatis框架基于映射文件和配置文件的方式,实现增删改查,可以打印日志信息
    Mybatis框架基于注解的方式,实对数据现增删改查
    java中的泛型和sql中的索引
    SpringMVC框架下的异常处理
    SpringMVC框架下的拦截器
    在SpringMVC框架下实现数据的国际化(即数据实现多国文字之间的转换)
    Java 随机数生成工具RandomUtils
    Java 获取客服端ip地址
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/14650337.html
Copyright © 2020-2023  润新知