zoukankan      html  css  js  c++  java
  • GIT Learning

    一、Why Git

    1.1 Git是分布式的,本地的版本管理

        chect out代码后会在自己的机器上克隆一个自己的版本库,即使你在没有网络的环境,你仍然能够提交文件,查看历史版本记录,创建项目分支,等不需要远程或架设服务器就能做到本地版本管理.

    1.2 不污染子目录的track文件

         svn每个子目录都要扔一个.svn.这个实在是.. .(我想很多人都碰到过svn lock folder的情况.实在让人气急败坏.实际上.svn文件就是罪魁祸首.各种clean up无果. delelte后svn up异常.真是.. 摔!.去你妹的svn.)

    1.3 强大的branch

         超轻量级的branch建立.(实际只是建立文件指针).推荐根据的git workflow的开发流程.将workspace分成几区.master dev feature hotfix区等.开发层次就出来了.

    1.4 merge工具的强力

        git根据commit ticket依次再进行一次merge.提高了merge成功率.避免svn merge中的难堪.即使merge失败.也不会生成乱七八糟的版本文件.简单修改后.commit就是.

    二、 Git安装配置

    2.1 安装
       ubuntu: sudo apt-get install git
       windows: 去 http://code.google.com/p/msysgit/ 下载安装
    2.2 配置文件

        你可以在.gitconfig文件中防止git的全局配置。文件位于用户的home目录。 上述已经提到每次提交都会保存作者和提交者的信息,这些信息都可以保存在全局配置中。

    2.3 配置用户信息
             
    # Configure the user which will be used by git
    # Of course you should use your name
    git config --global user.name "Example Surname"
    # Same for the email address
    git config --global user.email "your.email@gmail.com"
    # Set default so that all changes are always pushed to the repository
    git config --global push.default "matching"
    2.4 查看配置信息
             
    git config --list
    2.5 SSH Keys

        SSH key 可以让你在你的电脑和 Git @ OSC 之间建立安全的加密连接。

        生成sshkey

       

    # Creates a new ssh key using the provided email
    ssh-keygen -t rsa -C "xxxxx@xxxxx.com"

        在~/.ssh/id_rsa.pub中是生成的public key,复制文件中的全部内容并把他添加到ssh公钥管理中, Git @ OSC 的公钥管理页面如下链接: http://git.oschina.net/keys.

    三. Git库管理

    3.1 clone
       可以clone命令去clone别人公开的代码了。     
             
    git clone git://git.kernel.org/pub/scm/git/git.git

        image

    3.2 创建仓库,添加文件,提交修改

       

    # Initialize the local Git repository
    git init
    # Add all (files and directories) to the Git repository
    git add .
    # Make a commit of your file to the local repository
    git commit -m "Initial commit"
    # Show the log file
    git log

        先添加修改文件到提交索引,之后才能进行提交。

    3.3 添加远程库

    要添加一个新的远程仓库,可以指定一个简单的名字,以便将来引用,运行 git remote add [shortname] [url]

             
     $ git remote add pb git://github.com/paulboone/ticgit.git
     $ git remote -v
    origin git://github.com/schacon/ticgit.git pb git://github.com/paulboone/ticgit.git
    3.4 从远程仓库抓取数据

        格式: git fetch [retmote-name]

       

    git fetch pb
    3.5 推送数据到远程仓库

        格式: git push [remote-name]

         git push origin test:master         // 提交本地test分支作为远程的master分支
         git push origin test:test              // 提交本地test分支作为远程的test分支

       

    git push pb master:testing
    3.6 分支
    #新建分支test
    git branch test                     
    #切换到test分支
    git checkout test                 
    #将本地的test推送到远端    
    git push origin test:test         
    #切换到master分支
    git checkout master             
    #将test分支合并到master分支
    git merge test                     
    #删除本地test分支
    git branch -d test              
    #左面为空,远程的test分支将被删除
    git push origin :test              
    

    image

    四. SVN迁移到GIT

    4.1 先建立users.txt,格式如下:

        gr = ge rui <forgerui@gmail.com>

    4.2 或者通过以下命令获取用户列表(需要perl支持)
    $ svn log --xml | grep -P "^<author" | sort -u | 
        perl -pe 's/<author>(.*?)</author>/$1 = /' > users.txt
    4.3 获取svn版本库信息:
    $ git svn clone http://192.168.135.115:8080/svn/fpp
        --authors-file=users.txt --no-metadata -s fpp
    4.4 将所有的旧分支都变成真正的 Git 分支,所有的旧标签也变成真正的 Git 标签

        进入到项目的目录,运行如下命令:

    $ cp -Rf .git/refs/remotes/tags/* .git/refs/tags/
    $ rm -Rf .git/refs/remotes/tags
    $ cp -Rf .git/refs/remotes/* .git/refs/heads/
    $ rm -Rf .git/refs/remotes
    4.5 新增远程服务器
    git remote add myproject git@git.oschina.net:bairuiworld/myproject.git
    4.6 让所有分支标签都上传
    git push myproject --all

    欢迎访问我的个人主页: www.forgerui.tk

  • 相关阅读:
    java图片压缩 、图片缩放,区域裁剪,水印,旋转,保持比例。
    java树形菜单实现
    vue-resource的使用,前后端数据交互
    如何在IntelliJ IDEA中使用.ignore插件忽略不必要提交的文件
    Git以及TortoiseGit的下载安装使用
    springBoot总结
    idea如何设置类头注释和方法注释
    (document).height()与$(window).height()
    使用js对中文进行gbk编码
    JS中URL编码参数(UrlEncode)
  • 原文地址:https://www.cnblogs.com/gr-nick/p/3391105.html
Copyright © 2011-2022 走看看