zoukankan      html  css  js  c++  java
  • 常用的git和repo命令

    首先下图是git的流程图

    相关概念

    svn与git命令的对比

    git常用命令

    git log // 查看当前库的git log信息
    git status ./ // 查看当前库的状态
    git diff ./ // 比较当前库的修改情况
    git add ./ // 将当前库的代码修改提交到暂存区
    git commit ./ // 将代码提交到本地分支
    git commit --amend ./ // 追加修改
    git reset HEAD~1 // 将当前库恢复到HEAD的上一个版本

    其他命令

    git config -l // 参看配置信息
    git show HEAD^ // 查看HEAD的上一个版本信息
    git show HEAD~4 // 查看HEAD的上溯4代的信息
    git reset --hard HEAD^^ // 回退两个版本
    git reset --hard 8308f03 // 回退到指定的commitID前7位的版本
    git clean -dfx //清除库上没有的东西

    git remote -v // 参看远程仓库
    git branch -a // 参看远程分支
    git log --oneline --decorate --graph --all // 图像显示git log信息
    git log --pretty=format:"%h - %cd %s" --graph // 列出指定格式的log
    git log -since="2 weeks ago" // 显示2周前到现在所有的历史记录

     远程同步

    # 下载远程仓库的所有变动
    $ git fetch [remote]

    # 显示所有远程仓库
    $ git remote -v

    # 显示某个远程仓库的信息
    $ git remote show [remote]

    # 增加一个新的远程仓库,并命名
    $ git remote add [shortname] [url]

    # 取回远程仓库的变化,并与本地分支合并
    $ git pull [remote] [branch]

    # 上传本地指定分支到远程仓库
    $ git push [remote] [branch]

    # 强行推送当前分支到远程仓库,即使有冲突
    $ git push [remote] --force

    # 推送所有分支到远程仓库
    $ git push [remote] --all

    撤销

    # 恢复暂存区的指定文件到工作区
    $ git checkout [file]

    # 恢复某个commit的指定文件到暂存区和工作区
    $ git checkout [commit] [file]

    # 恢复暂存区的所有文件到工作区
    $ git checkout .

    # 重置暂存区的指定文件,与上一次commit保持一致,但工作区不变
    $ git reset [file]

    # 重置暂存区与工作区,与上一次commit保持一致
    $ git reset --hard

    # 重置当前分支的指针为指定commit,同时重置暂存区,但工作区不变
    $ git reset [commit]

    # 重置当前分支的HEAD为指定commit,同时重置暂存区和工作区,与指定commit一致
    $ git reset --hard [commit]

    # 重置当前HEAD为指定commit,但保持暂存区和工作区不变
    $ git reset --keep [commit]

    # 新建一个commit,用来撤销指定commit
    # 后者的所有变化都将被前者抵消,并且应用到当前分支
    $ git revert [commit]

    # 暂时将未提交的变化移除,稍后再移入
    $ git stash
    $ git stash pop

    repo常用命令

    repo init -u URL -b ........ // 创建.repo

    repo upload // 将代码提交到gerrit.

    repo abandon master // 放弃master分支

    repo forall -c "git reset --hard HEAD" // 所有代码执行git命令,回退到HEAD

    // repo sync相当于git clone会把repository中的所有内容拷贝到本地,非首次运行repo sync相当于更新和合并.
    // repo sync会更新.repo下面的文件,如果在merge的过程中出现冲突,这需要手动运行git rebase --continue.
    repo sync -c -j 4

    repo start master --all // 创建新分支

    其他帮助参考

    git使用的更详细参考: 可以百度“Pro Git 中文版”这个很不错的资料。

    另外可以利用工具自带的帮助功能查询常用命令:

    repo help
    git help
    git help [command]

  • 相关阅读:
    [JXOI2018]游戏
    UltraISO制作启动盘安装CentOS7
    龙芯、鲲鹏、飞腾等国产平台的浏览器
    浏览器相关性能测试网址
    有没有一种组合字体,中文是宋体,英文是times new roman?
    中国航天科工集团第二研究院706所招聘
    华为云
    面试阿里P6难在哪?(面试难点)
    Linux下配置环境变量—— .bashrc 和 /etc/profile
    Linux 内存 占用较高问题排查
  • 原文地址:https://www.cnblogs.com/qxfy/p/12030473.html
Copyright © 2011-2022 走看看