zoukankan      html  css  js  c++  java
  • git 操作---总结备忘

    git  操作

    一、标签类操作

      a、git 加标签:

               git tag -a v1.0 -m '新版本要出来了,备份老版本'

               即可创建一个tag

          b、git 显示标签

               git tag //显示当前所有tag

          c、git 显示标签详细信息

              git show v1.0 //显示v1.0版本的详细信息

    二、branch分支类操作

          a、新建分支

               git checkout -b new_branch     // 新建并切换到新分支

               git branch new_branch  //这也是一种新建分支的方式,不过它不会自动checkout的新的分支

               提示:新建分支时,要注意当前所在分支,如果当前在master,则生成一份master拷贝的分支,如果在子分支下新建,则生成子分支的一份拷贝。

        b、删除分支

               git branch -d  'new_branch'  //换成 -D,表示强制删除

         git branch -d  -r  'new_branch'  //删除远程分支

          c、显示所有分支

               git branch  //列出本地分支

         git branch -r   //列出远程分支

               git branch -a   //列出所有分支(本地和远程)

        d、重命名分支

               git branch -m old_name new_name  // 换成-M,表示强制换名  

               git branch -m haha wuwu  //haha 换成 wuwu

    三、误删检出

          a、未commit & push

               git  checkout page.css

          b、删除后,还push了,按tag找回

               git checkout v1.1 page.css

    四、origin(原始点)和master(主分支)、head

          在clone后,Git 会自动将远程仓库命名为origin(origin只相当于一个别名,运行git remote –v或者查看.git/config可以看到origin的含义),并下载其中所有的数据,建立一个指向它的master 分支的指针,我们用(远程仓库名)/(分支名) 这样的形式表示远程分支,所以origin/master指向的是一个remote branch(从那个branch我们clone数据到本地),因此你无法在本地更改其数据。

          同时,Git 会建立一个属于你自己的本地master 分支,它指向的是你刚刚从remote server传到你本地的副本。随着你不断的改动文件,git add, git commit,master的指向会自动移动,你也可以通过merge(fast forward)来移动master的指向,即其他分支合并到master一次,master会向前走一次,表示master有变化了。

          head相当于一个指针,指向当前所在的branch。     

              

    五、pull指定远程分支

          有时候,我们的分支还在修改不想push(好像必须提交),又想看看和别人的分支有啥区别,可以用这个方式:

          git branch -r    //先查看远程分支,看看别人提交的分支叫啥名字

          git pull  origin  test_branch  //pull某个特定分支,并合并test_branch分支到当前分支,origin表示远程你clone时的起始点,注意,当前状态必须是commit过的。

          git checkout -b test_discuz_ucenter origin/test_discuz_ucenter  //pull远程分支,不合并

          git pull 默认回去合并与当前分支同名的分支,如果加后面的分支名test_branch,就表示合并到当前分支了~

     六、git全局变量配置

      git config -l  //查看当前全局信息

      git config --global user.email "your@email.com"

      git config --global user.name "yourname"

      git config --global core.editor vim //默认编辑器换成vim

          

    补充:

    $git branch -a (to show all the branches git knows about)

    * master

      remotes/origin/HEAD -> origin/master

      remotes/origin/master

     

    $git branch -r (to show remote branches git knows about)

      origin/HEAD -> origin/master

      origin/master

     

    可以发现,master就是local branchorigin/masterremote branchmaster is a branch in the local repository. remotes/origin/master is a branch named master on the remote named origin

    $git diff origin/master master show me the changes between the remote master branch and my master branch).

    需要注意的是,remotes/origin/masterorigin/master的指向是相同的

    $git diff origin/master remotes/origin/master

     

    git push origin master

    origin指定了你要push到哪个remote

    master其实是一个“refspec”,正常的“refspec”的形式为”+<src>:<dst>”,冒号前表示local branch的名字,冒号后表示remote repository branch的名字。注意,如果你省略了<dst>git就认为你想pushremote repository下和local branch相同名字的branch。听起来有点拗口,再解释下,push是怎么个push法,就是把本地branch指向的commit pushremote repository下的branch,比如

    $git push origin master:master (local repository中找到名字为masterbranch,使用它去更新remote repository下名字为masterbranch,如果remote repository下不存在名字是masterbranch,那么新建一个)

    $git push origin master (省略了<dst>,等价于“git push origin master:master”)

    $git push origin master:refs/for/mybranch (local repository中找到名字为masterbranch,用他去更新remote repository下面名字为mybranchbranch)

    $git push origin HEAD:refs/for/mybranch HEAD指向当前工作的branchmaster不一定指向当前工作的branch,所以我觉得用HEAD还比master好些)

    $git push origin :mybranch (再origin repository里面查找mybranch,删除它。用一个空的去更新它,就相当于删除了)

    备注:

    mac 下git clone 命令失败:

    xcrun: error: invalid active developer path

    问题是:CommandLineTools 没有安装

    so安装it:xcode-select --install   即可 

     相关连接:

      http://hi.baidu.com/mvp_xuan/item/afde021353b973f8756a84d1  //git操作

      http://lishicongli.blog.163.com/blog/static/1468259020132125247302/  //origin master

      

    1、以专家为榜样,不必自己重新探索
    2、解构技能,找出实现80%效果的那20%
    3、不要一心二用
    4、练习练习再练习!然后获得即时反馈
    5、坚持,不要在低谷期放弃
  • 相关阅读:
    Flask程序相关配置加载的三种方式
    Redis数据库在windows系统下的安装及使用
    Redis数据库介绍
    python中模块的制作
    4.ORM框架的查询
    3.ORM框架一对多的关系及使用
    2.ORM框架添加,修改,删除操作
    1.ORM介绍,基本配置及通过ORM框架创建表
    4.集合
    3.字典
  • 原文地址:https://www.cnblogs.com/zhongyuan/p/3497971.html
Copyright © 2011-2022 走看看