Git version management use - introduction - example

Git is a version control tool that helps programmers organize and manage the history of code changes

The following are the basic concepts and usage of Git:

  1. Warehouse (Repository): Git uses the warehouse to store the historical change records of the code, including all code files and version information. A Git repository can be stored on a local computer or a remote server.

  2. Branch (Branch): Git allows programmers to create multiple different branches in the same warehouse, and each branch can contain different versions of the code. Programmers can develop and experiment on different branches, and finally merge the codes of different branches.

  3. Commit: The basic unit of Git is Commit, and each commit is a snapshot of a modification or a series of modifications to the code. Each commit contains a unique identifier, along with metadata such as who made the commit and when it was committed.

  4. Pull (Pull): Git allows programmers to pull code from a remote warehouse to a local computer in order to view and modify the code. Using the pull function requires first connecting to the remote repository and gaining access.

  5. Push (Push): To push local code changes to remote warehouses, programmers need to use the push function. Push uploads all local commits to the remote repository.

  6. Merge: When the codes of two branches conflict, programmers can use Merge to merge the codes of the two branches together. Conflicts need to be resolved when merging, keeping the code from both branches.

  7. Tag (Tag): Git allows programmers to tag a version in the code repository. Tags are generally used to identify a version or an important milestone for easy search and backtracking.

How to use Git:

  1. First create a new Git repository on your local computer or remote server;
  2. Add code files to the repository;
  3. Use the submit function to save the modification of the code file to the warehouse;
  4. Use the branch function to create multiple different branches in the same warehouse for development and experimentation;
  5. Use the pull and push function to connect to the remote warehouse and push the code from the local to the remote warehouse;
  6. Use the merge function to merge code from different branches together;
  7. Use the tagging feature to tag for easy lookup and backtracking.

common commands

Create warehouse

git init initializes the warehouse
git clone copies a remote warehouse, that is, downloads a project.

Submit and modify

git add Add files to the warehouse
git status View the current status of the warehouse and display changed files.
git diff compares the difference between files, that is, the difference between the temporary storage area and the work area.
git commit Submit the temporary storage area to the local warehouse.
git reset rollback version.
git rm removes workspace files.
git mv moves or renames workspace files.
Submit log
git log View historical submission records
git blame View historical modification records of specified files in list form

remote operation

git remote remote warehouse operation
git fetch Get code base from remote
git pull download remote code and merge
git push upload remote code and merge

Install Git software

Go here to download the Git download address , select the version you need to download and install;
after installation, you can directly open the command to enter your project; or in your project directory, right click and select Git Bash Here to open
git

Open it and configure your user name and mailbox. This is a global configuration, which will write all the warehouses on this computer. Of course, you can set different ones for a certain warehouse.

git config --global user.name "名字"
git config --global user.email "邮箱"

first upload

Follow the process, first initialize the warehouse, and generate a .git hidden folder in the working directory

git init

Add all the files in the directory to the local warehouse (.) means all, you can also specify the file name to add

git add .

Associate remote warehouse

git commit -m "1.0"

Commit the file to the repository

git remote add origin 刚刚的地址

Push all the contents of the local library to the remote library

git push -u origin master

the branch

Upload an independent branch (for example, the code is DOWNLOAD ZIP file directly from the project, which is independent of the original MASTER branch)

1. git init (in the local project directory)
2. git add .
3. git commit -m "luyang" ("luyang" is the branch name)
4. git branch luyang (create branch)
5. git checkout luyang (switch branch )
6. git remote add origin http://192.168.36.10:10080/quantum_rng_testing/nist ("quantum_rng_testing/nist" is the directory of the project, this time do not need the following .git suffix)
7. git push origin luyang (upload the branch )
Note: If you are prompted "please tell me who you are"
in the config file in the .git directory, add
[user]
name = xxxx
email = [email protected] at the end

This creates a branch and uploads the

merge branch

git merge ginger

merge branch
Then go to the remote warehouse to see if the merge is successful. If not, execute the following command:

git push --force origin master

merge branch

delete branch

After the merge, the branch can be deleted, which can be deleted in the branch management of the remote warehouse
or executed

git branch -d 分支名称

Guess you like

Origin blog.csdn.net/qq_68862343/article/details/131999350