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.
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
- SVN: also known as subversion, is the successor of CVS and is a
- 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
- GIT: A
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
- distributed
Version 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 directory
Repository (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: 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
When multi-person development requires a
shared version library
, initialization for single-person development A- local library
- can be used
The 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
: 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
- Configure email:
-
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
- git status
- 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
- (Note that there is a dot at the end. )
- 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到远程服务器
>>>>>> 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
- 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"
- ssh -T git@github.com
7. Use SSH Key operation GitHub
oschina use
- The method is the same as GitHub
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!

GitHub是一个面向开源及私有软件项目的托管平台,可以让开发者们在这里托管自己的代码,并进行版本控制。GitHub主打的是开源项目与协作,通过这个平台上的开源项目,开发者们可以查看其他开发者的项目源代码,并进行交流和学习。

在git中,“push -u”的意思是将本地的分支版本上传到远程合并,并且记录push到远程分支的默认值;当添加“-u”参数时,表示下次继续push的这个远端分支的时候推送命令就可以简写成“git push”。

GitLab是一种基于Web的Git版本控制库管理软件,旨在帮助开发团队更好地协同工作,提高工作效率。当您第一次登录GitLab时,系统会提示您要更改初始密码以确保账户安全。本文将为大家介绍如何在GitLab上进行第一次登录并更改密码。

在git中,pack文件可以有效的使用磁盘缓存,并且为常用命令读取最近引用的对象提供访问模式;git会将多个指定的对象打包成一个成为包文件(packfile)的二进制文件,用于节省空间和提高效率。

git中pull失败的解决方法:1、利用“git reset --hard”强制覆盖掉自己的本地修改;2、利用“git stash”推送一个新的储藏,拉取之后利用“git stash pop”将修改保存到暂存区;3、若依然出现问题,则将文件保存到暂存区并提交注释即可。

git分支能改名字。改名方法:1、利用git中的branch命令修改本地分支的名称,语法为“git branch -m 旧名字 新名字”;2、利用“git push origin 新名字”命令,在删除远程分支之后将改名后的本地分支推送到远程;3、利用IDEA直接操作修改分支名称即可。

git删除某个分支的方法:1、利用“git branch --delete dev”命令删除本地分支;2、利用“git push origin --delete branch”命令删除远程分支;3、利用“git branch --delete --remotes”命令删除追踪分支。

本篇文章给大家带来了关于git的相关知识,其中主要跟大家聊一聊怎么让你的git记录保持整洁,感兴趣的朋友下面一起来看一下吧,希望对大家有帮助。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
