zoukankan      html  css  js  c++  java
  • git --- 持续更新

    东转西转

    git

    1 git 使用

    1.1 git 安装

    ~$: sudo apt-get install git

    1.2 git 初始化

    ~$: git init
    ~$: git remote add origin https://github.com/username/xxxx.git 
    ~$: git config --global user.name "yourname"
    ~$: git config --global user.email youremail@example.com
    

    1.3 git 常用命令

        git status        查看仓库状态,显示上次递交之后本地的文件变动以及临时递交,注意这里比较的是同一节点间的变动。
        git diff         尚未缓存的改动
        git diff  --cached 查看已缓存的改动
        git diff  HEAD     查看已缓存的与未缓存的所有改动
        git log          查看历史记录
        git log origin/<branch-name> 查看远程分支递交记录
        git stash        把当前的工作隐藏起来 等以后恢复现场后继续工作
        git stash list   查看所有被隐藏的文件列表
        git stash apply  恢复被隐藏的文件,但是内容不删除
        git stash drop   删除文件
        git stash pop    恢复文件的同时 也删除文件
        git remote       查看远程库的信息
        git fetch        更新远程数据到本地
        git merge        合并本地分支
        git pull <remote> <localbranch>   同步远程代码到本地
            实际上git fetch+git merge=git pull动作
        git push origin master  Git会把master分支推送到远程库对应的远程分支上
            push -u origin master 注意-u参数,表示选择upstream,一个branch可以对应多个upstream,-u参数是选择你的默认upstream,以后使用git fetch/git pull/git rebase时就可以不用加参数了,一般是使用在第一次git push时 。官方文档表示参考git config的branch.<name>.merge的相关内容
        git add -A .     所有变更文件添加到缓存区
        git commit       将缓存区的变更更新到仓库
        git show <commit checksum>   显示commit校验和对应的修改
        git reset  HEAD^ 撤销至上个递交记录
        git reset  --hard <commit checksum> 
                         撤销/回退到相应checksum的commit,注意当前代码的备份,该操作会覆盖当前的代码
        git rm           将文件从缓存区移除
    

    2.git 本地使用流程

        git clone git@github.com:username/uboot.git //克隆远程代码到本地
        git add -A . //将本地代码的变更添加到git缓存中
        git commit -m "add uboot" //提交变更到本地git
        git push origin master //同步到远程主机
        在远程仓库为空,且本地仓库有新文件的情况下可以使用一下方式:
        git init
        git add .
        git commit -m "xxxx"
        git remote add origin git@github.com:username/uboot.git
        git push -u origin master

    3.fork项目相关操作

    1.更新自己 Fork 的代码项目和原作者的项目进度一致的方法:
        原项目地址:https://github.com/gozfree/libraries.git
        1)将fork到github上的项目clone到本地
            git clone https://github.com/feisonzl/libraries.git
            cd libraries
        2)添加 gozfree 项目的地址,也就是主项目的 remote 地址
            git remote add gozfree https://github.com/gozfree/libraries.git
            git fetch gozfree
            git merge gozfree/master
        3)将原作者的项目跟新到我的github中
            git commit -m '更新到原作者的主分支的进度'
            git push origin

    4.git patch生成和使用

        1.git diff方法
        git diff > name.patch  生成patch
        git diff --cached > name.patch
        git diff branch-name --cached > name.patch
        git apply name.patch 应用patch
    
        2.git format-patch
        git format-patch -M master 生成patch
        git am ***.patch 应用patch

    5.git status问题:

    当clone到用户端的文件被更改权限后,git status会爆出很多modify
    解决方法:更改.gitconfig文件中的filemode=true改为false
     

     6. git 版本回退

    先显示提交的log

    $ git log -3
    commit 4dc08bb8996a6ee02f
    Author: Mark <xxx@xx.com>
    Date:   Wed Sep 7 08:08:53 2016 +0800
    
        xxxxx
    
    commit 9cac9ba76574da2167
    Author: xxx<xx@qq.com>
    Date:   Tue Sep 6 22:18:59 2016 +0800
    
        improved the requst
    
    commit e377f60e28c8b84158
    Author: xxx<xxx@qq.com>
    Date:   Tue Sep 6 14:42:44 2016 +0800
    
        changed the password from empty to max123

    回滚到指定的版本

    git reset --hard e377f60e28c8b84158

    强制提交

    git push -f origin master

    repo

    1.repo常用命令

    1.repo init –u URL [OPTIONS] //检出清单版本库
        options:
            -u:指定一个URL,其连接到一个maniest仓库
            -m:在manifest仓库中选择一个xml文件
            -b:选择一个maniest仓库中的一个特殊的分支
        例:repo init -u 172.16.16.121:manifest -b msm8909 -m qcom_msm8909.xml 
    2.repo sync //同步版本库
    3.repo start  <newbranchname> [--all | <project>…]  //创建并切换分支
    4.repo checkout     //切换分支
    5.repo branches     //查看分支
    6.repo diff         //查看工作区文件差异
    7.repo stage        //把文件添加到index表中
    8.repo status       //查看文件状态
    

    2.repo常用操作流程

        repo init -u gitserver:manifests.git -m xxx.xml (xxx.xml文件决定初始化的项目)
        repo sync 
        repo start xxx --all //创建xxx项目对应的分支 (--all意为将所有模块都归为当前xxx分支下)
        git add xxx
        git commit -m "xxx"
        repo upload

    3.repo切换分支

        cd .repo/manifests
        ls //查看xxx.xml文件
        cd .. //回到上级目录
        ln -s  manifest.xml manifests/QK_CM298_EXER.xml //更换manifest.xml的软连接
        cd ..
        repo sync //同步代码
        repo start xxx--all//建立本地分支

    4. 自己踩过的坑

    1.部分子目录中的文件push后,远程依然没有的情况
        最近在使用git push时,发现怎么push,远程都无法同步本地子目录下的文件,困扰了我两天时间,最后发现是因为子目录中也有.git文件夹,因为该目录是我之前pull的别人的,一直没注意。这种情况,push是不会同步含有.git文件夹的子目录的。
  • 相关阅读:
    CentOS 6.3 下编译Nginx(笔记整理)
    XMPP协议相关基础概念(Strophe学习笔记)
    StackMapTable format error
    hibernate的子查询
    strophe与openfire模拟的XMPP简单hello程序
    Strophe.Status的所有值
    博客园添加SyntaxHighlighter
    P5395 【模板】第二类斯特林数·行
    test20191001
    test20190829
  • 原文地址:https://www.cnblogs.com/jlmgary/p/9047459.html
Copyright © 2011-2022 走看看