Home > Article > Development Tools > Thirty minutes to get you started with Git (summary)
This article brings you relevant knowledge about getting started with git, including environment configuration, basic theory, project construction, file operations and other related issues. I hope it will be helpful to everyone.
Recommended study: "Git Getting Started Tutorial"
Version control (Revision control) is a method used to manage our files, directories or projects during the development process. Modification history, easy to view change history, backup software engineering technology to restore previous versions.
Simply put, it is a technology used to manage multi-person collaborative development projects.
Without version control or lack of correct process management in this province, many problems will be introduced in the software development process, such as the consistency of software code, redundancy of software content, and transactional nature of software processes. Issues such as concurrency in the software development process, security of software source code, and software integration.
The mainstream version controllers are as follows:
Version control products (Perforce, Rational ClearCase, RCS (GNU Revision Control System), Serena Dimention, SVK, BitKeeper, Monotone, Bazaar, Mercurial, SourceGear Vault), the most influential and widely used ones now are Git and SVN.
Record every update of the file. You can make a snapshot of each version, or record patch files, suitable for personal use, such as RCS.
All version data is saved on the server, and collaborative developers can update or upload their own modifications synchronously from the server.
All version data is stored on the server. The user's local only has the version that he has synchronized before. If he is not connected to the Internet, the user cannot see the historical version, nor can he switch version verification issues or work in different branches. . Moreover, all data is stored on a single server. There is a high risk that this server will be damaged and all data will be lost. Of course, it can be backed up regularly. Representative products: SVN, CVS, Vss.
Each branch has all the code.
All version information warehouses are synchronized to each local user, so that all version history can be viewed locally and submitted locally offline, and only need to be pushed to the corresponding server or other users when connected to the Internet. Since each user saves all version data, as long as there is no problem with one user's device, all data can be restored, but this increases the occupation of local storage space.
It will not be unable to work due to server damage or network problems.
SVN is a centralized version control system. The version library is centralized on the central server, and when working, They all have their own computers, so they must first get the latest version from the central server, and then work. After completing the work, they need to push last night's work to the central server. A centralized version control system must be connected to the Internet to work, and requires high network bandwidth.
GIT is a distributed version control system without a central server. Each computer is a complete version library. There is no need to connect to the Internet when working, because the versions are all on the computer. The method of collaboration is this: For example, if you change file A on your computer and someone else also changes file A on your computer, then you two only need to push your modifications to each other, and you can see each other. has been modified. Git can directly see which code and files have been updated.
Git is currently the most advanced distributed version control system in the world.
Open the Git official website https://git-scm.com and download the version of git corresponding to the operating system.
If everything is slow to download, you can find a mirror!
The official website download is too slow, you can use Taobao mirror download: http://npm.taobao.org/mirrors/git-for-windows/
Git Bash: Unix and Linux-style command line, most used and recommended
Git CMD: Windows-style command line
Git GUI: Git with graphical interface, not Recommended for beginners, try to be familiar with common commands
cd: change directory
cd..Return to the previous page A directory, directly cd to enter the default directory
pwd: Display the current directory path
ls(ll): List all files in the current directory, but the contents listed by ll are followed by For details
touch: Create a new file such as touch index.js and a new index.js file will be created in the current directory
rm: Delete a file
mkdir: Create new A directory is a new folder.
rm-r: delete a folder, rm-r src deletes the src directory
mv moves the file
reset re-initializes the terminal and clears the screen
clear clear screen
historyView command history
help
exit exit
#Indicates comment
All configuration files are actually saved locally
Set user name and email address:
git config --global user.name "Name"
git config --global user.email 22222@qq.com
git config --system --list Query the configuration configured by the system
git config --global --list Query the global configuration
Git has three local working areas: working directory (Working Directory), staging area (Stage, Index), and resource library (Repository or Git Directory). If you add the remote git warehouse (Remote Directory), it can be divided into four work areas. The conversion relationship between files between these four areas is as follows:
To be precise, the three local areas should be the versions pointed to by HEAD in the git warehouse:
The workflow of git is generally as follows:
1. Add and modify files in the working directory;
2. Put the files that need version management into the staging area;
3. Submit the files in the staging area to the Git warehouse.
Therefore, files managed by git have three states: modified, staged, and committed.
Creating a working directory and common instructions
The working directory (WorkSpace) is generally what you want Git to help you manage. The folder can be the directory of your project or an empty directory. It is recommended not to contain Chinese characters.
For daily use, just remember the 6 commands below:
Create a local There are two ways to create a warehouse: one is to create a brand new warehouse, and the other is to clone a remote warehouse.
1. To create a brand new warehouse, you need to use the root directory of the project managed by GIT to execute:
#在当前目录新建一个Git代码库 $ git init初始化
2. After execution, you can see that there is only one more .git directory in the project directory, about the version All the information etc. are in this directory.
1. Another way is to clone the remote directory, because it will completely mirror the pants on the remote server to the local one!
#可镂一个项目和它的整个代码历史(版本信息) $ git clone [url]
2. Go to gitee or github to clone a test
Version control It is the version control of files. To modify and submit files, you must first know the current status of the files. Otherwise, you may submit files that you do not want to submit yet, or files that you want to submit may not be submitted.
It is said that the file has four states. You can check the file status through the following command:
#查看执行文件状态 git status [filename] #查看所有文件状态 git status #添加所有文件到暂存区 git add . #提交暂存区中的内容到本地仓库 -m提交信息 git commit -m "注释内容"
Sometimes we don’t want to include certain files into version control, such as database files, temporary files, design files, etc.
Create ".gitignore" in the main directory " file, this file has the following rules:
#为注释 *.txt #忽略所有 .txt结尾的文件,这样的话上传就不会被选中 !lib.txt #但lib.txt除外 /temp #进忽略项目根目录下的TODO文件,不包括其他目录temp build/ #忽略build/目录下的所有文件 doc/*.txt #忽略doc/notes.txt 但不包括 doc/server/arch.txt
.gitignore file content
#java *.class *.log *.lock #Package Files # *.jar *.war *.ear target/ # idea .idea/ *.iml *velocity.log* ### STS ### .apt_generated .factorypath .springBeans ### IntelliJ IDEA ### *.iml *.ipr *.iws .idea .classpath .project .settings/ bin/ *.log tmp/ #rebel *rebel.xml*
# 进入 C:\Userss\Administrator\.ssh 目录 # 生成公钥 ssh-keygen -t rsa
3. Add the public key information public key to the code cloud account!
4. Use Code Cloud to create your own warehouse
1. Create a new project and bind git
Integrate the remote git Just copy the file directory to the project or create it in the git directory with the same name (git file is a remotely cloned git file)
The idea will appear after refreshing
2. Modify the file and use IDEA to operate git
3. Submit test
Common instructions in git branch
#列出所有本地分支 git branch #列出所有远程分支 git branch -r #新建一个分支,但仍然停留在当前分支 git branch [branch-name] #新建一个分支,并切换到该分支 git checkout -b [branch] #合并指定分支到当前分支 git merge [branch] #删除分支 git branch -d [branch-name] #删除远程分支 git push origin --delete [branch-name] git branch -dr [remote/branch]
Recommended learning: "Git Tutorial"
The above is the detailed content of Thirty minutes to get you started with Git (summary). For more information, please follow other related articles on the PHP Chinese website!