table of Contents
Git, which was most developed in Linus, is on Linux, and some people slowly ported it. Now Git can run on Linux, Unix, Mac, and Windows platforms.
Install git on linux
First enter
git
Check if it has been installed and
then follow the instructions given by him to install
The way to compile the source code
Download the source code on the git official website, then
./config
make
sudo make install
Verify installation
Enter git
installation is complete
Configuration after installation
git config --global user.name "urname"
git config --global user.email “xxxxxxx@xxxxxxxxxx.com”
Because Git is a distributed version control system, each machine must self-report: your name and email address. You may be worried, what if someone pretends to be someone else on purpose? Don’t worry about this. First of all, we believe that everyone is a kind-hearted and ignorant mass.
Pay attention to the -global parameter of the git config command. Using this parameter means that all Git repositories on your machine will use this configuration. Of course, you can also specify a different user name and email address for a certain repository.
Create a repository
Repository is also known as warehouse. The English name of repository
can be simply understood as a directory. All files in this directory can be managed by Git. Git can track the modification and deletion of each file, so that the history can be tracked at any time. , Or you can "restore" at some point in the future.
Process
The first step is
to create an empty directory in a suitable place
mkdir learnGit
cd learnGit/
pwd
As you can see, in my virtual machine, the address of the warehouse is/home/p08/learnGit
Second step
git init
Use git init
instructions in this folder to turn this directory into a warehouse that git can manage
The warehouse is built in an instant, and it tells you that this is an empty warehouse
Input commandls -ah
You can see that there is a hidden folder here.
This directory is used by Git to track and manage the repository. It's okay. Don't manually modify the files in this directory. Otherwise, the mess will be changed and the Git repository will be destroyed.
It is not necessary to create a Git repository in an empty directory. It is also possible to choose a directory that already has things. However, it is not recommended that you use the company project you are developing to learn Git, otherwise you will not be responsible for all the consequences.
Add files to the repository
All version control systems can actually only track changes to text files , such as TXT files, web pages, all program codes, etc., and Git is no exception.
The version control system can tell you every change, such as adding a word "Linux" in line 5 and deleting a word "Windows" in line 8.
Although binary files such as pictures and videos can also be managed by the version control system, they cannot track the changes of the files . They can only string together each change of the binary files, that is, only know that the picture is changed from 100KB to 120KB, but in the end What has been changed, the version control system does not know, nor can it know.
Note: Microsoft's Word format is a binary format. Therefore, the version control system cannot track changes to Word files. The previous example is just for demonstration. If you want to use the version control system, you must write the file in plain text.
Add step
First
write one readme.txt文件
, the content is as follows:
Git is a version control system.
Git is free software.
Note: It must be placed in a
learnGit
directory or subdirectory. Because itlearnGit
is a Git repository, git finds files in the repository.
The first step is to
use git add
instructions to add files to the warehouse
git add readme.txt
As you can see, there is no report after running, that is no problem.
git add
Instructions can also add multiple files, separated by spaces.
The second step is to
use the git commit
instructions to submit the file to the warehouse
git commit -m "wrote a readme file"
git commit
After the command is executed successfully, it will tell you
- 1 file changed: 1 file has been changed (the readme.txt file we newly added)
- 2 insertions: Two lines of content have been inserted (readme.txt has two lines of content).
-m is git commit
the parameter of the instruction, and the quotation marks after it are remarks, which can be viewed through the git log
instruction.
Submitted
Possible errors
Q: input git add readme.txt
, get an fatal: not a git repository (or any of the parent directories)
error: .
A: Git commands must be executed in the Git warehouse directory ( git init
except), it is meaningless to execute outside the warehouse directory.
Q: I entered git add readme.txt
and got an error fatal: pathspec 'readme.txt' did not match any files
.
A: When adding a file, the file must exist in the current directory. Use the ls
or dir
command to view the files in the current directory to see if the file exists or if the file name is wrong.