Home  >  Article  >  Development Tools  >  Summarize and organize Git version control study guide

Summarize and organize Git version control study guide

WBOY
WBOYforward
2022-03-03 17:36:461819browse

This article brings you relevant knowledge about Git, which mainly summarizes the knowledge points of version control. Let’s take a look at the Git version control study guide. I hope it will be helpful to everyone. helpful.

Summarize and organize Git version control study guide

Recommended study: "Git Learning Tutorial"

The Origin of Version Control

  • Today’s software projects are usually analyzed, designed, coded, maintained and tested by a R&D team.
  • The following problems need to be solved for team development:
    • Backing up multiple versions consumes space. Time-consuming
    • It is difficult to restore to the previous correct version
    • It is difficult to resolve code conflicts
    • It is difficult to trace the modification time of the problematic code
    • Unable to perform permissions Difficulties in controlling
    • Project version release
  • The source code management tool came into being to solve the above problems

Revision Control (Revision Control )

  • is a standard practice for maintaining project blueprints, which can track the process of project blueprints from birth to finalization. It is a system that records changes in the content of several files so that you can check the revision of a specific version in the future
    • If it is a team development, the use of version control is mandatory!
    • If you are developing alone, it is strongly recommended to start using version control now!
  • You can use version control:
    • Will not cause any damage to existing work
    • Will not increase workload
    • When adding new functional extensions, it will become easier

Common version control tools

  • CVS opens the door to version control
    • CVS was born in 1990, the mainstream source code management tool in ancient times
  • SVN The King of Centralized Version Control
    • SVN: also known as subversion, is the successor of CVS and is a centralized source code management tool. It used to be the code management tool (google code) for most open source software. In the past few years, it was the most commonly used by domestic software companies
  • Great work of GIT distributed version control
    • GIT: A distributed source code management tool. At present, almost all domestic enterprises have completed the conversion from SVN to GIT

  • Centralized source code management

  • Distributed source code management

  • The biggest difference between distributed and centralized is:

    • Under centralized, developers can only submit code to the server, while under distributed, developers can submit locally
    • In centralized mode, there is only a code database on the remote server. In distributed mode, there is a code database on each developer machine.
  • SVN (centralized Formula)

  • GIT(distributed)

A simple comparison between Git and SVN

  • Speed
    • In many cases, git is far faster than SVN
  • Structure
    • SVN is centralized management, git is distributed management
  • Others
    • SVN is clumsy to use branches, git You can easily have unlimited branches
    • SVN must be connected to the Internet to work properly, git supports local version control
    • The old version of SVN will place a .svn in each directory, and git will only place a .svn in each directory. The root directory has a .git

##GIT Introduction

    GIT is a free and open source
  • distributedVersion control system for handling any small or large project agilely and efficiently
  • Among all the distributed version control tools in the world, git is the fastest, simplest, The most popular
  • is the second great work of Linus, the father of Linux. In 2005, BitKeeper software company stopped free use rights for the Linux community.
    • In order to assist the development of the Linux kernel (manage source code), Linus had to develop a distributed version control tool himself, and Git was born
  • Working Principle of GIT

If you want to learn GIT well, you must first understand the working principle of GIT

  • Working Directory:
  • Inside the warehouse folder , Contents other than
  • .git directoryRepository (Repository):
  • .git directory, used to store and record version information
  • Repository The staga in the repository:
    • The branch (master) in the repository:
    • The first branch
    • version automatically created by git **HEAD pointer in the library:** is used to point to the current branch
git add and git commit naming effects
    git add: Add file modifications to the buffer area
    • ##git commit: Submit all contents of the buffer area to the branch pointed to by the current HEAD pointer
    GIT usage environment

When multi-person development requires a

shared version library

, initialization for single-person development A
    local library
  • can be usedThe form of shared version library:Local shared library: folder/U disk/hard disk
  • Remote shared library: Build your own git server/host it on a third-party platform (github/oschina, etc.)
    • Whether it is single-person development or multi-person development, the client can be used using the command line or graphical interface git
  • GIT Command-Personal Development

git help
    : git command help manual
  • View other instructions: git help other instructions

    git init
  • : Warehouse initialization (personal warehouse)
  • Warehouse file directory

    HEAD:	指向当前分支的一个提交
    description:	项目的描述信息
    config:	项目的配置信息
    info/:	里面有一个exclude文件,指定本项目要忽略的文件
    objects/:	Git对象库(commit/tree/blob/tag)
    refs/:	标识每个分支指向哪个提交
    hooks/:	默认的hook脚本
    • GIT settings configuration information
  • Configure user name:

    git config user.name "Username"

    (for tracking modification records)
    • Configure email: git config user.email "Email" (for communication between multiple developers)
    • git config -l: View configuration information
    • git config -e: Edit configuration information
    • ##git status
    : Check the status of a file
  • Check the status of a certain file:git status file name

      Check the status of all files in the current path:
    • git status
    • ##git add
    • : Save the files in the workspace to the buffer area
  • Save A certain file to the buffer area:

    git add file name

    Save all files in the current path to the buffer area:
      git add .
    • (Note that there is a dot at the end. )
    • git commit
    • : Submit the file in the buffer area to the current branch
  • Submit a file to the branch:

    git commit -m "Comment" file name

    Save all files in the current path to the branch:
      git commit -m "Comment"
    • git log
    • : View the modification log of a file
  • View the modification log of a certain file:

    git log file name

    View the modification logs of all files in the current path:
      git log
    • View simple log information in one line:
    • git log ––pretty=oneline
    • View the latest N modifications:
    • git log –N
    • (N is an integer)
    • git diff
    • : View the latest changes to a file
  • View the latest changes to a file:

    git diff file name

    View all files in the current path The latest changes:
      git diff
    • git reflog
    • : View branch reference records (can view all version numbers)
  • git rm: Delete the file (commit operation is required after deletion to synchronize to the repository)

  • git reset: Version rollback (it is recommended to add the --hard parameter, git supports unlimited regrets)

    • 回退到上一个版本:git reset ––hard HEAD^
    • 回退到上上一个版本:git reset ––hard HEAD^^
    • 回退到上N个版本:git reset ––hard HEAD~N(N是一个整数)
    • 回退到任意一个版本:git reset ––hard 版本号(版本号用7位即可)
  • Git忽略提交规则 - .gitignore配置

    • 别看了, 你想要的都在这企业开发专用链接
#               表示此为注释,将被Git忽略*.a             表示忽略所有 .a 结尾的文件!lib.a          表示但lib.a除外/TODO           表示仅仅忽略项目根目录下的 TODO 文件,不包括 subdir/TODO
build/          表示忽略 build/目录下的所有文件,过滤整个build文件夹;
doc/*.txt       表示会忽略doc/notes.txt但不包括 doc/server/arch.txt
 
bin/:           表示忽略当前路径下的bin文件夹,该文件夹下的所有内容都会被忽略,不忽略 bin 文件
/bin:           表示忽略根目录下的bin文件
/*.c:           表示忽略cat.c,不忽略 build/cat.c
debug/*.obj:    表示忽略debug/io.obj,不忽略 debug/common/io.obj和tools/debug/io.obj
**/foo:         表示忽略/foo,a/foo,a/b/foo等
a/**/b:         表示忽略a/b, a/x/b,a/x/y/b等!/bin/run.sh    表示不忽略bin目录下的run.sh文件*.log:          表示忽略所有 .log 文件
config.php:     表示忽略当前路径的 config.php 文件 
/mtk/           表示过滤整个文件夹*.zip           表示过滤所有.zip文件/mtk/do.c       表示过滤某个具体文件
 
被过滤掉的文件就不会出现在git仓库中(gitlab或github)了,当然本地库中还有,只是push的时候不会上传。
 
需要注意的是,gitignore还可以指定要将哪些文件添加到版本管理中,如下:!*.zip!/mtk/one.txt
 
唯一的区别就是规则开头多了一个感叹号,Git会将满足这类规则的文件添加到版本管理中。为什么要有两种规则呢?
想象一个场景:假如我们只需要管理/mtk/目录中的one.txt文件,这个目录中的其他文件都不需要管理,那么.gitignore规则应写为::/mtk/*
!/mtk/one.txt
 
假设我们只有过滤规则,而没有添加规则,那么我们就需要把/mtk/目录下除了one.txt以外的所有文件都写出来!
注意上面的/mtk/*不能写为/mtk/,否则父目录被前面的规则排除掉了,one.txt文件虽然加了!过滤规则,也不会生效!
 
----------------------------------------------------------------------------------
还有一些规则如下:
fd1/*
说明:忽略目录 fd1 下的全部内容;注意,不管是根目录下的 /fd1/ 目录,还是某个子目录 /child/fd1/ 目录,都会被忽略;
 
/fd1/*
说明:忽略根目录下的 /fd1/ 目录的全部内容;
 
/*
!.gitignore
!/fw/ 
/fw/*
!/fw/bin/
!/fw/sf/
说明:忽略全部内容,但是不忽略 .gitignore 文件、根目录下的 /fw/bin/ 和 /fw/sf/ 目录;注意要先对bin/的父目录使用!规则,使其不被排除。

GIT命令-团队开发

  • git init --bare : 仓库初始化(共享仓库)
    • 注意: 不要直接在共享仓库中编写代码
  • git clone:下载远程仓库到本地
    • 下载远程仓库到当前路径:git clone 仓库的URL
    • 下载远程仓库到特定路径:git clone 仓库的URL 存放仓库的路径
  • git pull:下载远程仓库的最新信息到本地仓库
  • git push:将本地的仓库信息推送到远程仓库
    • 提交时如果远程仓库有其它人提交的最新代码, 必须先pull, 再提交
  • 冲突解决:
    • 当多个人同时修改了同一个文件时, 后提交的需要先从服务器pull代码到问题, 手动解决完冲突之后再push到远程服务器
<<<<<<< HEAD
	你本地的新增的代码=======
	服务器上和你冲突的代码>>>>>>> e9609de28b65bf97539f94c6458cdebdf2711c9f

GIT经典协同模型

  • 中心仓库:包含master和develop两个分支

  • 分支分类

    • 主要分支:master和develop分支
    • 支持性分支:特性分支,发布分支,热补丁分支
  • 对于商业级项目,真正开发过程中都是基于develop分支进行的,develop分支是开发主线!

  • master分支中,只存放相对稳定的分支,例如:0.1版本, 0.2版本

  • 在实际产品开发中,需要“规划版本”,例如:将100个功能规划到5个不同的版本上

  • 发现bug,要基于“上一个最稳定的版本”进行修复,这是热补丁分支存在的意义!

  • 理解清楚版本管理分支的特性,是迭代式开发的重要基础!

  • git branch : 查看所有分支

  • git branch 分支名称 : 创建分支

  • 新创建的分支中的内容和master分支中的内容一样
  • git checkout 分支名称 : 切换到指定分支
  • git merge 分支名称 : 合并分支
    • 将当前所在分支和指定名称分支进行合并
  • git branch -d 分支名称 : 删除指定分支
  • 不能在当前分支中删除自己

使用GIT我们应该

  • 经常更新:降低冲突的可能性
  • 提交前需在本机测试通过:降低将问题代码传到版本库
  • 提交时一定写备注:方便其他员工查看和自己以后回顾
  • 对于不需要提交的文件不要提交到版本库

提示:

  • Update before each submission
  • Submit the code compiled that day before leaving get off work every day
  • The first thing to do every day at work is to update the code of the previous day

GITHUB USING

  • 1. Register a GitHub account
  • ##2.Log in to GitHub
  • 3. Click on your warehouse
  • 4. Create a new warehouse
  • 5. The new warehouse can be downloaded, but submission requires an account and password
  • 6. Configure SSH Key
    • 6.1 Open the git command line tool
    • Enter the command
    • ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
    • 6.2 Copy the public key just generated
    • 6.3 Add the generated SSH Key to GitHub
    • 6.4 Test whether the configuration is successful
    • ssh -T git@github.com
    • If it appears later: Hi ****! You've successfully authenticated, but GitHub does not provide shell access. Prove success
  • 7. Use SSH Key operation GitHub

oschina use

    The method is the same as GitHub
Recommended learning: "

Git Tutorial"

The above is the detailed content of Summarize and organize Git version control study guide. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete