zoukankan      html  css  js  c++  java
  • 理论篇 GIT使用笔记

      GIT学习指导的游戏:http://pcottle.github.io/learnGitBranching/?NODEMO

      git fetch: 下载远端所有分支的本地没有的提交列表,并更新local分支origin/master

      1. 从remote下载local resp未包含的提交对象

      2. 更新local resp的远端分支点(如: origin/master)

      git fetch origin remoteBranch:localBranch  // 下载远端的分支到本地分支

      git fetch orign :localNewBranch       // 不指定Source时创建本地新分支 

      合并local resp的两个分支,有以下方式:

      1. git cherry-pick o/master

      2. git rebase o/master

      3. git merge o/master

      git pull: 就是git fetch与git merge origin/master的组合;

      1. 下载并更新local origin/master;

      2. 将local分支origin/master合并到local的当前分支中;

      注:如果要替换pull默认的merge操作,可以使用:git pull --rebase(当然rebase是从当前分支到origin/master分支中,因为remote提交的可能会很多;如果本地很多,remote少,可以反过来)

      git push: 提交local的当前分支 到remote的该分支中,并更新local的origin/master分支;

      1. 提交local的当前分支 到remote的该分支中

      2. 更新local的origin/master分支

      A先checkout remote的mater分支到local的master分支,开发new feature;B此后多次提交到remote的master分支;A要提交之前,必先下载合并代码,确保代码工作无误后,才提交:

      1. git fetch 更新local的origin/master分支;

      2. git rebase origin/master 以origin/maste为主分支,衍合当前分支master,此时master比origin/master多前进了feature提交;测试功能或者再提交;

      3. git push 提交到remote,并更新local的origin/master分支;

      注:如果将步骤2的rebase替换为merge,那么在步骤3的push中,remote也会做merge操作;

       关于让某个分支HEAD快速前进:

      master分支的head在C1,feature1分支的head在C2,C1 --> C2,想要将master的head移到C2上,可以:git rebase feature1 master(以feature1分支为主干,衍合其它分支)

      git rebase feature1: 都是以feature1分支为主分支,衍合当前分支master;

      git rebase feature1 master :都是以feature1分支为主分支,衍合master分支;

      1. 按提交顺序:如果master在feature1的上面,则将master的HEAD前移,即:快速前进;

      2. 按提交顺序:如果master与feature1并列,则复制master的更新,HEAD指向最新提交;

      3. 按提交顺序:如果master在feature1的下面,则提示:分支已经是最新的!

      跟踪远端分支:

      git checkout -b newBranchName o/master

      git branch -u o/master existedBranchName    // 重新设置upstream. (-u)

      将本地master分支的提交列表,推送到origin仓库的master分支中;

      git push origin master

      将本地分支或者HEAD指向的提交,推送到origin仓库的已存在分支或者新分支中;

      git push origin localBranch^:remoteNewBranch

      不指定source时,删除分支localBranch

      git push origin :localBranch

      remoteBranch下载到localBranch中,再在当前正在工作的branch中,merge localBranch。

      git pull origin remoteBranch:localBranch

      <<Pro Git>>学习笔记:

      本地工作目录的三种状态:

      已提交 commited --> 已修改 modified --> 已暂存 staged

    命令:
    git config

    // 添加别名
    git config --global alias.<short> <full-name>


    git clone                  // 从远程仓库下载到本地目录

    git status                  // 工作目录中各文件的状态:“已修改”、“已暂存”

    状态变更:
    git add <file>                 // 放到暂存区,处于“已暂存”

    git commit -m "commitMessage"      // 提交文件,状态为:"已提交"

    git commit -a -m              // 跳过暂存,直接提交

    git rm <file>                // 从暂存区移除文件
    git rm <file> -f               // 永久移除该文件,待提交
    git rm <file> --cache            // 保存该文件,不提交
    git reset head <file>            // 取消"已暂存",恢复到工作目录

    git commit --amend -m msg        // 修改最后一次提交:将"暂存区"覆盖上次的提交,弥补上次的部分缺失
    git checkout <file>             // 取消"已修改",恢复到上次最新的代码


    远程仓库:
    git remote -v                // 查看远程仓库
    git remote add <name> <url>       // 添加远程仓库

    git remote show <remote-repository-name>  // 查看某个远程仓库的详细信息

    git remote rename <old-name> <new-name>  // 更改远程仓库的名字


    git fetch <remote-name>          // 从远程仓库抓取数据到本地

    // 本地推送到远程仓库的某个分支上
    git push <remote-repository-name> <remote-branch-name>

    // 将所有本地标签上传过去
    git push <> <> --tags


    分支管理:

    git branch -a            // 查看本地所有分支

    git branch <branch-name>      // 创建分支

    git branch -d <branch>       // 删除分支(-D 强制删除)

    git checkout <branch>       // 切换分支(切换工作目录到某一个分支)

    git checkout -b <branch>      // 创建分支,并切换到该分支

    git checkout -b <branch> <remote-resp>/<remote-branch>

    git merge <branch>        // 将branch合并到当前分支中;

    git push <remote-resp> <branch> // 将分支推送到远程仓库的该分支下

    git push <remote-resp> <branch>:<remote-branch>  // 将分支推送到远程仓库的某branch下

    git push <remote-resp> :<remote-branch>       // 删除远程仓库下的branch

    git rebase <branch>      // 将当前分支,衍合到branch中

  • 相关阅读:
    [转]更新到Android 3.0 虚拟机启动时窗口太大 的调整
    云 实例 之 http://www.salesforce.com/cn/
    [转]步步为营 .NET 代码重构学习笔记 一、为何要代码重构
    忽弃工资及周边 自我人生 需在付出中获得 必在实践中成长
    [转]Android开发中插入新的Activity
    [转]How to Create HTML5 Website and Page Templates for Visual Studio 2010
    MogileFS is an open source distributed filesystem
    [转] HTML 5 Intellisense for Visual Studio 2010 and 2008
    [转]eclipse android : A project with that name already exists in the workspace
    android 在manifest 中设置 多个Activity时的 默认 根 Activity
  • 原文地址:https://www.cnblogs.com/diydyq/p/4103007.html
Copyright © 2011-2022 走看看