• Can work offline
  • It’s easier to work with others
  • Branching is easy
  • It’s easy to merge
  • Git systems are fast and flexible

Git architecture

repository

A series of files, directories, history, commit records, and header Pointers. Think of it as each source code file with a history attribute data structure

A Git repository consists of a.git directory and its working directory

.git directory (part of the repository)

The.git directory contains all configuration, logs, branch information, header Pointers, etc

Working directory (part of the repository)

The directories and files in the repository can be thought of as your working directory

Index (.git directory)

An index is a staging area in Git. Is it a layer that separates your working directory from your Git repository, giving developers more flexibility in deciding what to add to the repository

submit

A Git commit is a snapshot of a set of changes or operations to a working directory. For example, if you add 5 files, delete 2 files, those changes will be written to a commit. These changes are then written into a commit that can then be pushed to another repository

branch

A branch is just a pointer to your last commit and when you commit, that pointer will automatically point to the last commit

Header pointer and header (.git folder function)

A header pointer is a pointer to the current branch. A repository has only one active header pointer and the header can point to any commit in the repository. Each repository can also have multiple heads

The command

Initialize the

Create a new Git version library. The repository configuration, storage, and other information is stored in the.git folder

$ git init
Copy the code

configuration

Change Settings. This can be a repository setting, system or global

$git config --global user.email $git config --global user.name $git config --global user.email "[email protected]" $ git config --global user.name "My Name"Copy the code

state

Shows the difference between the index file (that is, the current workspace) and the commit to which the current header pointer points

$git status $git help status $git help statusCopy the code

add

Adds a file to the current workspace. If you don’t use git add to add files, they won’t be added to future commits

Add a file # $git add HelloWorld. Java # add file in a subdirectory $git add/path/to/file/HelloWorld. C # support regular expression $git add. / *. JavaCopy the code

branch

To manage branches, run the following commands to add, delete, modify, and query branches

$git branch -d myNewBranch $git branch -d myBranch $git branch -m myBranchName myNewBranchName $git branch myBranchName --edit-descriptionCopy the code

Check out the

Updates the current workspace to the one identified by the index or to a specific workspace

$git checkout branchName = "git branch < name > "; Git checkout < name >" $git checkout -b newBranchCopy the code

clone

This command copies one repository to another directory and copies all branches to the new repository. This allows you to commit to a remote branch in a new version library

# clone xxx-docs
$ git clone https://github.com/xxx/learnxxx-docs.git
Copy the code

commit

Saves the changes to the current index as a new commit that contains the changes and information made by the user

$git commit -m "Added multiplyNumbers() function to helloworld.c"Copy the code

diff

Displays the difference between the current workspace and the commit

$git diff: $git diff: $git diff: $git diff: $git diff: $git diff: $git diff: $git diff: $git diffCopy the code

log

Displays all commits for this version library

$git log -n 10 $git log --mergesCopy the code

merge

Merge is the merging of external commits into its own branch

$git merge branchName $git merge branchName $git merge branchNameCopy the code

mv

Rename or move a file

$git mv helloworld.c./new/path/ helloWorld.c $git mv -f myFile existingFileCopy the code

pull

Merge from the remote repository to the current branch

$git pull origin master $git pull origin masterCopy the code

push

Update the remote version library

$git push $git push $git push $git push $git push $git push $git push $git pushCopy the code

rm

As opposed to add, remove a file from the workspace

# remove the HelloWorld. C $git rm HelloWorld. C # remove files in the directory $git rm/pather/to/the/file/HelloWorld. CCopy the code

reference

git-scm.com/docs