一、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

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

四. 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

GIT Learning的更多相关文章

  1. Git Learning - By reading ProGit

    Today I begin to learn to use Git. I learn from Pro Git. And I recommend it which is an excellent bo ...

  2. Git Learning Part III - working remotely (Github)

    help document of Github : https://help.github.com/ 1 upload 1.1 new update  Initialize a repository  ...

  3. Git Learning Part II - Working locally

    file status life circle basic: modified:   Examples: untracked: unmodified: modified: Git branching ...

  4. Git Learning Part I - Install Git and configure it

    Why we need 'Git' GIt version control: 1. record the history about updating code and deleting code 2 ...

  5. git 学习(1) ----- git 本地仓库操作

    最近在项目中使用git了,在实战中才知道,以前学习的git 知识只是皮毛,需要重新系统的学一下,读了一本叫  Learn Git in a Month of Lunches 的书籍,这本书通俗易懂,使 ...

  6. Git初级

    一,安装git 一键安装 Mac 或 Windows. 二,下载一个工具书 Git 命令手册 free Git cheat sheet 三,安装完成之后需要先配置两个基本配置:用户名和邮箱 $ git ...

  7. Git/Github Learning

    通过网上查找资料,我了解到Git/Github是一款免费.开源的分布式版本控制系统,它可以敏捷高效地处理任何或小或大的项目.同时,它是一个开源的分布式版本控制系统,用以有效.高速的处理从很小到非常大的 ...

  8. Learning Git by Animations

    https://hujiaweibujidao.github.io/blog/2016/05/20/learning-git-by-animations/ http://learngitbranchi ...

  9. Git命令回顾

    团队从Eclipse迁移到Android Studio之后,也从SVN迁移到Git了. 一直忙于需求迭代无暇做迁移,现在才开始做,相见恨晚,好东西,高大上,词穷. 回顾和记录一下git的一些基本操作. ...

随机推荐

  1. Wunder Fund Round 2016 (Div. 1 + Div. 2 combined) A. Slime Combining 水题

    A. Slime Combining 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=2768 Description Your frien ...

  2. Codeforces Round #338 (Div. 2) A. Bulbs 水题

    A. Bulbs 题目连接: http://www.codeforces.com/contest/615/problem/A Description Vasya wants to turn on Ch ...

  3. Microsoft.AlphaImageLoader滤镜解说

    Microsoft.AlphaImageLoader是IE滤镜的一种,其主要作用就是对图片进行透明处理.尽管FireFox和IE7以上的IE浏览器已经支持透明的PNG图片,可是就IE5-IE6而言还是 ...

  4. Python之美[从菜鸟到高手]--深刻理解原类(metaclass)

    本来想自己写这篇文章的,可当我读了这篇文章http://blog.jobbole.com/21351/,我打消了这个念头,因为肯定写的没有人家的好,说的通俗易懂,面面俱到.就厚着面皮修改下格式,测试下 ...

  5. 海量数据处理算法—Bit-Map

    原文:http://blog.csdn.net/hguisu/article/details/7880288 1. Bit Map算法简介 来自于<编程珠玑>.所谓的Bit-map就是用一 ...

  6. 关于解决Permission is only granted to system apps

    一句话,clean一下这个Project!就OK了…… 不要被假象迷惑!

  7. jquery 请求apache solr 跨域解决方案

    <script type="text/javascript" src="js/jquery-1.7.2.min.js"></script> ...

  8. framework&&library's root

    框架和文件集合的路径应该是相对路径而不是绝对路径 写法如下图所示:

  9. C#三大支柱之继承

    1.使用base 若子类需要使用父类公开或受保护的成员则需要是base class Manager : Employee { public int StockOptions { get; set; } ...

  10. [经典算法] 蒙地卡罗法求 PI

    题目说明: 蒙地卡罗为摩洛哥王国之首都,该国位于法国与义大利国境,以赌博闻名.蒙地卡罗的基本原理为以乱数配合面积公式来进行解题,这种以机率来解题的方式带有赌博的意味,虽然在精确度上有所疑虑,但其解题的 ...