Version tool management----GIT

Source: Internet
Author: User
Tags git workflow svn update using git git commands

How to view hidden folders:

If you don't see the. git directory, you need to make the hidden files visible. This is done by opening a terminal window and entering the following command:

Defaults write Com.apple.finder appleshowallfiles TRUE

In order to restart the Finder app, enter:killall finder

source code control tools-git I. Git overview1. Introduction to Git?
    1. What is Git?

       > git是一款开源的分布式版本控制工具 > 在世界上所有的分布式版本控制工具中,git是最快、最简单、最流行的
    2. The origins of Git?

       > 作者是Linux之父:Linus Benedict Torvalds > 当初开发git仅仅是为了辅助Linux内核的开发(管理源代码)
    3. What's the status of Git?

       > 在国外已经非常普及,国内并未普及(在慢慢普及) > 越来越多的开源项目已经转移到git
2. What are the common source control tools?
> CVS    - 开启版本控制之门    - 1990年诞生,“远古时代”的主流源代码管理工具> SVN    - 全称是Subversion,集中式版本控制之王者    - 是CVS的接班人,速度比CVS快,功能比CVS多且强大    - 在国内软件企业中使用最为普遍(70%-90%)> ClearCase    - 收费的集中式版本控制工具,安装比Windows还大,运行比蜗牛还慢    - 能用ClearCase的一般是世界500强,他们有个共同的特点是财大气粗或者人傻钱多> VSS    - 微软的集中式版本控制工具,集成在Visual Studio中
3. Centralized version control

all the code is in one piece, unified management

4. Distributed version control

Each client has a complete code repository that can be managed on a per-client

5. Simple comparison of Git and SVN
> 速度    在很多情况下,git的速度远远比SVN快> 结构    SVN是集中式管理,git是分布式管理> 其他    SVN使用分支比较笨拙,git可以轻松拥有无限个分支    SVN必须联网才能正常工作,git支持本地版本控制工作    旧版本的SVN会在每一个目录置放一个.svn,git只会在根目录拥有一个.git
6. SVN workflow vs. git workflow
- svn checkout —— git clone    svn 只下载代码, git 会连同代码仓库一起下载下来- svn commit —— git commit    svn 是提交到服务器,git 中是提交到本地仓库,需要使用push才能提交到服务器-  svn update - git pull    都是从服务器下载最新被修改的代码

The biggest difference between distributed and centralized is that, under distributed, there is a local code repository where developers can submit locally; Centralized version control, only the server has a code warehouse, only the server for unified management

7. How Git Works
    1. Conceptual understanding

       - 工作区     > 与.git文件夹同级的其他文件夹或者子文件夹 - 版本控制库     > 暂缓区     > 分支(Git不像SVN那样有主干和分支的概念. 仅仅存在分支,其中master分支为默认被创建的分支,类似于SVN中的主干)         切换分支:通过控制HEAD指针指向不同的分支,就可以切换*

Operating principle: All newly added/deleted/modified files must be added to the pause area before they can be submitted to the current branch of the head point

8. Git usage Environment
    1. Single-player development requires only one local library

       原因:不需要与他人共享代码,只负责管理自己代码即可;例如提交代码,删除代码,版本控制等等
    2. A shared repository is required for multi-person development

       共享版本库的形式:     本地共享库:文件夹/U盘/硬盘     远程共享库:自己搭建git服务器/ 托管到第三方平台(例如github, oschina)
    3. Use the environment whether it is single-player or multi-person development, the client can use the command line or graphical interface using Git

        > SourceTree      - :http://www.sourcetreeapp.com/download/  > GitHub      - :https://mac.github.com      - 不过它是专门为GitHub网站而设计的  > Xcode      - 虽然集成较好,但是只能做一些常用的简单操作,复杂操作还要使用命令行
two. Git command-line Walkthrough-Personal development0. How to learn git commands
    > git help [子命令]    > 和学习SVN指令是一样的,只不过git是通过使用指南的形式展示给用户看(不能编辑的vim编辑器),使用q退出vim编辑器,按空格进入下一页,ctrl + B 回到上一页; /关键字 进行搜索
1. Initialize a local repository
    > 原因: 管理本地代码,修改上传,版本回退    > 命令: git init
2. Configure the Warehouse
    > 告诉git你是谁?        原因: 追踪修改记录        命令: git config user.name “shunzi”    > 告诉git怎样联系你?        原因: 多人合作开发时, 沟通交流        命令: git config user.email "[email protected]"    > 查看配置信息(.git -> config打开)        命令:  git config -l
3. Personal development Drills
    > 创建文件并提交        命令:             touch main.c            git add .             git commit -m “注释”    > 修改文件并提交         命令:             git add .            git commit -m “注释”    > 删除文件并提交        命令:             git rm person.h            git commit -m “注释”    > 日志查看        命令:             git log             git reflog    > 版本回退        命令:             git reset —hard HEAD 重置到当前版本            git reset —hard HEAD^^ 重置到上上个版本            git reset ——hard HEAD2 重置到往上2个版本            git reset —hard 七位版本号 重置到指定版本::
5. Supplementary notes
    1. File status (Git status)

       > 颜色含义     红色: 代表被添加或者修改的文件没有被添加到暂缓区     绿色: 代表文件在暂缓区,等待提交 > 版本号的含义     版本号是一个由SHA1生成的40位哈希值     这样做的目的是保证版本号的唯一
    2. Use of the VIM editor

        命令模式:等待编辑命令输入;所有输入的内容都被当做命令来执行  插入模式:输入的所有内容都被显示,并被当做文件内容处理  命令行模式:执行待定命令(保存文件并退出vim : wq   ; 强制退出不保存: q! )
    3. Log View Configuration

       命令如下:      git config --global alias.lg "log --color --graph --pretty=format:‘%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)\<%an\>%Creset‘ --abbrev-commit"
    4. Configure aliases

       git config alias.st “status” git config alias.ci “commit -m”
    5. The role of--global

       可以进行全局配置,所有的版本库共享此配置 查看全局配置(桌面前往->个人->.gitconfig ** 个人电脑上建议使用全局配置**
three. Git command-line Walkthrough-Team development

Team development must have a shared library so that members can collaborate on development

0. Shared library classification
    > 本地共享库(只能在本地面对面操作)        - 电脑文件夹/U盘/移动硬盘    > 远程共享库(可通过网络远程操作)        - 自己搭建Git服务器(**不建议**)        - 在Github上托管项目(** 建议**)            Github网址(https://github.com); 公开项目免费, 私有项目收费        - 在OSChina上托管项目(** 推荐**)            OSChina网址(https://git.oschina.net) 安全免费,在国内访问速度快
1. Build a local shared library
    原因: 多人合作开发,代码共享    命令: git init —-bare
2. Manager initialize project to local shared library
    命令: git clone 本地代码仓库地址
3. Demo Multiplayer Development
    > 创建文件夹manager, niuda        命令:            mkdir manager             mkdir niuda    > 分别进入到两个文件夹从共享库clone项目到本地        命令:            git clone 本地代码仓库地址            git clone 本地代码仓库地址    > 演练新增文件同步        命令:            touch person.h            git add .                 git commit -m “创建person.h”            git push                git pull    > 演练修改文件同步        命令:            git add .             git commit -m “注释”            git push            git pull    > 演练删除文件同步        命令:            git rm filename            git commit -m “注释”            git push                   git pull    > 演练冲突解决        命令:            git pull    > 演练忽略文件        命令:            touch .gitignore               open .gitignore   加入忽略文件名            git add .                 git commit -m “注释”        .gitignore文件配置规则            http://www.cnblogs.com/haiq/archive/2012/12/26/2833746.html
4. Note Notes
    > 关于忽略文件        在真实开发中,配置.gitignore文件 , 去github里面搜索gitignore 选择OC版本的,拷贝到本地仓库即可,记得添加到本地版本库    > 常见问题        fetch first 代表当前文件过期,需要从远程共享库更新         git pull
four. Git-xcode Walkthrough-Team Development1. Build a local shared repository
命令: git init —-bare
2. Manager initialize project to shared repository
** 注意: 添加忽略文件, 不然Xcode有可能会把没必要的文件提交**** 必须在使用Xcode之前把忽略文件添加进来, 因为Xcode创建工程时, 默认直接把所有文件添加到暂缓区, 加进去之后忽略文件对其就无效了**
3. Cow and ox Two use Xcode to clone Project 4. Walkthrough adds file synchronization 5. Walkthrough modifies file synchronization 6. Walkthrough Removing file synchronization 7. Walkthrough ConflictsFive. Use of GitHub1. Managed Project to GitHub
    1. Open GitHub website: [https://www.github.com]
    2. Registered account (Oneshunzi)
    3. Click Create New Warehouse [Https://github.com/new]
    4. Fill in the project name, description and other information
    5. Create complete
    6. Can be cloned based on the generated repository address
2. How to join a partner
    1. Click "Personal", setting, ssh keys, Add ssh key
    2. Add the public key generated by your little partner. (The following is a method for generating the public key private key) [https://help.github.com/articles/generating-ssh-keys/]
3. How do I add other well-known frameworks to our code warehouse?
    1. Search for a corresponding frame
    2. Click Fork
    3. When the project is moved to its own code warehouse, it can be cloned and manipulated according to the address.

       ** 注意:     你可以针对此框架进行任意修改,但是仅仅作用在你的本地仓库中的副本,对原作者项目没有任何影响.      如果想向原作者提建议,可以直接使用,pull request操作.     提交完成后,原作者可以在pull request中看到你的提交.至于是否采纳,就是原作者的意愿
Six. Use of Oschina1. Managed Project to Oschina
    1. Open Oschina website: [Https://git.oschina.net]
    2. Registered account (Oneshunzi)
    3. Click Create New Warehouse [Https://git.oschina.net/projects/new]
    4. Fill in the project name, description and other information
    5. Create complete
    6. Can be cloned based on the generated repository address
2. How do I join a partner?
    1. Click Manage, Project member management, select Member permissions to create
    2. or simply SSH (the following is the method of generating the public key private key)

           > 部署公钥允许以只读的方式访问项目,主要用于项目在生产服务器的部署上,免去HTTP方式每次操作都要输入密码和普通SSH方式担心不小心修改项目代码的麻烦。     > [https://help.github.com/articles/generating-ssh-keys/]
3. How do I add other well-known frameworks to our code warehouse?
    1. Search for a corresponding frame
    2. Click Fork
    3. When the project is moved to its own code warehouse, it can be cloned and manipulated according to the address.

       ** 注意:     你可以针对此框架进行任意修改,但是仅仅作用在你的本地仓库中的副本,对原作者项目没有任何影响.      如果想向原作者提建议,可以直接使用,pull request操作.     提交完成后,原作者可以在pull request中看到你的提交.至于是否采纳,就是原作者的意愿
Seven. New Server Setup
    1. New server Building conceptual reasons?

       概念: 搭建一个临时共享版本库, 供新人专用 原因: 防止新人刚到时,搞乱服务器上的项目
    2. Create a new folder, Newbee, as a new server

    3. Go to folder use Git Init--bare initialize warehouse
    4. Manager opens the folder where his project is located, performs pull, updates to the latest
    5. Then source control-Project master--Configure project

       > 选择Remotes 选项 代表当前所连的远程服务器地址 > 点击+号 添加 将newBee文件路径作为另外一个远程服务器地址 file:// 协议开头 结尾以/结尾 > Done
    6. The manager submits the latest code to the new remote repository

    7. Manager assigns new server address to new person
    8. New kinds of Toss
    9. Manager to create folder, download code check from new server
    10. Graphic

eight. Git version backup/branch management

in Git, the backup and the open branch are not solved by copying code. git directly tags, through the control head point, back and forth to any version

1. Version Backup
    1. Create a shared library

       > 创建文件夹shareWeibo > 进入文件夹后,初始化共享库     git init ——bare
    2. Manager after cloning the Project 1.0 version, after the tag, upload the shared library

       > 创建manager文件夹 > 进入文件夹后     git clone 共享库绝对路径 > 进入工作区,配置姓名,邮箱     git config user.name “manager”     git config user.email “[email protected]” > 经理创建文件,并修改部分代码,提交代码,上传到共享库,完成v1.0版本     touch main.c     open main.c:: 打开后写入abc     git add .     git commit -m “完成1.0版本开发”     git push > 经理给此版本打标签,并将标签上传到共享库     git tag -a v1.0 -m “标记1.0版本”     git push origin v1.0 > 经理继续开发2.0版本......并提交     git add .     git commit -m “2.0部分功能”     git push
2. Released version bug fix

Do the following on the basis of the above steps

    1. Cow Big Clone Project, create a branch based on version 1.0, fix bugs

       > 创建niuda文件夹 > 进入文件夹后     git clone 共享库绝对路径 > 进入工作区,配置姓名,邮箱     git config user.name “niuda”     git config user.email “niuda[email protected]” > 根据v1.0版本建立新分支v1.0fixbug并切换到此分支     git checkout v1.0 -b v1.0fixbug:: > 修复bug后提交到本地版本库

      Note that this is the branch that the head points to-v1.0fixbug

           git add .     git commit -m “修复bug”
    2. After the bull fix the bug, hit label v1.1 for version backup, and upload the shared library

       git tag -a v1.1 -m “1.1版本备份” git push origin v1.1
    3. Cow Big upload entire branch to shared repository

       git push origin v1.0fixbug

——— to this point, the branch fix bug ends and the following manager merges the branch ———

    1. Manager updates code from shared library to local library

       git pull
    2. Manager to see which branches are present on the server

       git branch -r
    3. After the manager switches to the master branch, merge the V1.0fixbug branches.

       git checkout master git merge origin/v1.0fixbug -m “合并分支”
    4. Submit to Shared library when manager merge is complete

       git add . git commit -m “合并分支” git push
    5. After the merge is complete, you can delete the branch of the shared library

       git branch -r -d origin/v1.0fixbug
    6. Check the Version tab to the end!!

       git tag

Version tool management----GIT

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.