• Git常用命令


    1. 安装Git,配置信息

    配置本机用户名,和邮箱

    git config --global user.name "<name>" 
    git config --global user.email "<email>"        
    

    2. 创建版本库

    cd到合适的目录

    # 初始化为git仓库
    git init
    

    3. 版本控制

    3.1 增删文件

    # 增加或更新监控文件(file为文件名,文件夹名, * . )
    git add <file>
    
    # 取消监控文件
    git rm <file>
    
    # 查看哪些文件使用clean后将删除
    git clean -n
    
    # 删除untracked(未监控)的文件,一般在pull后才会使用!
    git clean -f
    
    # 删除untracked(未监控)的文件和目录,一般在pull后才会使用!
    git clean -df
    

    3.2 本地提交

    # 查询工作空间状态
    git status
    
    # 查询不同
    git diff
    
    # 本地提交(desc简要描述这次的提交)
    git commit -m "<desc>"
    
    # (没add&commit)丢弃修改(file为文件名,文件夹名都可)
    git checkout -- <file>
    
    # (add&commit)丢弃暂存区修改
    git reset HEAD <file>
    

    3.3 回退

    # 查看日志(可以最后加数字,显示最近几个)
    git log
    
    # 查看简要日志
    git log --pretty=oneline
    
    # 回退到上一个版本
    git reset --hard^
    
    # 回退到上100个版本
    git reset --hard~100
    
    # 回退到版本号指定的版本,不需要输入完整
    git reset --hard <commit_version>
    

    3.4 远程库推送

    # 创建SSH Key,然后把id_rsa.pub添加到GitHub账户内
    ssh-keygen -t rsa -C "<email>"
    
    # 关联远程库(git用户名/远程库名)
    git remote add origin git@github.com:<gitname/rep>
    
    # 第一次推送至远程仓库(branch_name为master或分支名)
    git push -u origin <branch_name>
    
    # 推送至远程仓库
    git push origin <branch_name>
    
    # 从远程库克隆
    git clone <clone_address>
    
    # 拉取远端并合并本地仓库
    git pull
    
    # 合并多个commit,将后面的commit合并到前面,并重写commit message
    git rebase -i <commit_version>
    

    3.5 分支管理

    # 查看当前分支
    git branch
    
    # 拉取远程分支
    git fetch origin <origin_branch_name>:<local_branch_name>
    
    # 切换分支
    git checkout <branch_name>
    
    # 创建并切换分支
    git checkout -b <branch_name>
    
    # 删除分支
    git branch -d <branch_name>
    
    # 合并其他分支
    git merge <other_branch_name>
    
    # 合并其他分支的某个提交
    git cherry-pick <commit_version>
    
    # 推送分支到远程仓库
    git push origin <branch_name>
    git push origin <local_branch_name>:<origin_branch_name>
    
  • 相关阅读:
    plsql Developer11的工具栏没有了如何找回来
    postman发送HTTP请求自动生成MD5/SHA1签名
    Redis的安装+哨兵模式+集群
    SpringBoot笔记 --- @JsonFormat和@DateTimeFormat的作用
    HBase异常 -- hbase list报错 ERROR: org.apache.hadoop.hbase.PleaseHoldException: Master is initializing
    Windows使用进阶
    SpringBoot笔记 -- @RequestParam、@RequestBody、@PathVariable、@param
    SpringBoot笔记 -- 注解
    Mybatis笔记 -- 批量操作(查询、插入、更新、删除)
    Git异常 -- 汇总
  • 原文地址:https://www.cnblogs.com/haoabcd2010/p/11583773.html
Copyright © 2020-2023  润新知