zoukankan      html  css  js  c++  java
  • Git 常用操作

    1. 取消 merge

    1) 先用 git reflog 查看操作日志

    2) 使用 git reset --hard HEAD@{x} 强制回到你需要的分值 

    2. 创建新分支

    git checkout -b newBranch

    3. 提交到远程分支

    git push origin newBranch

    4. 将本地分支指向远程分支

    git push -u origin newBranch

    5. 将当前分支提交到新分支

    git push origin HEAD:newBranch

    6. 批量取消 add

    例如批量取消 .iml 文件的 add

    git reset HEAD $(git ls-files | grep .iml)

    7. 暂存当前修改

    git stash 暂存当前修改

    切换到其他分支, 修改, 切回原来分支

    git stash list 查找暂存内容

    git stash apply stash@{1} 恢复暂存内容

    8. 显示远程服务信息

    git remote show origin

    origin 为远程 repository 名

    9. 添加远程分支

    git remote add <别名> <url>

    10. 初始化项目

    # 克隆项目到本地
    git clone git@gitlab.corp.qunar.com:campus2015/training2.git
    
    # 切换到 training2
    cd training2
    
    # 新建分支并切换到新的分支, 现在这个分支在本地, newBranch 是分支名, 请根据自己的需要命名自己的分支
    git checkout -b newBranch
    
    # 回到上一级目录
    cd ..
    
    # mvn 初始化项目, 这一步可能会比较慢, 可以使用 idea 新建项目替代这一步
    mvn archetype:generate -DgroupId=com.qunar.training -DartifactId=training2 -Dversion=1.0.0 -DinteractiveMode=false -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=5-SNAPSHOT
    
    # 进入项目目录
    cd training2
    
    # 添加本地未添加的文件 pom.xml 和 src 文件夹
    git add pom.xml src
    
    # 提交一次
    git commit -m 'first commit'
    
    # push 到远程分支 newBranch
    git push -u origin newBranch
  • 相关阅读:
    【20171030早】sqli-libs Less7-15 练习
    【20171029中】sqli-libs 注入的过程 less1-4
    【20171028早】ubuntu 16.04 LTS 安装php遇到的问题
    【20171027早】alert(1) to win 第9,10,11,12题
    【20171026早】alert(1) to win
    【20171025晚】alert(1) to win 第五题 正则表达式过滤
    【20171025中】alert(1) to win 脚本渲染自建
    【20171025早】alert(1) to win 练习
    mysql 导入 excel 数据
    我的书单
  • 原文地址:https://www.cnblogs.com/zemliu/p/3711829.html
Copyright © 2011-2022 走看看