[Git common control commands GitHub Gitee code hosting platform]

[Git GitHub Gitee version control and code hosting platform]

Tip: After the article is written, the table of contents can be automatically generated. How to generate it can refer to the help document on the right

(article directory)


foreword

Recalling the beginning of the freshman year, the professional teacher asked us to register Gitee (code cloud) and use the basic commands and operations of Git. This includes creating code repositories, adding and committing files, branch management, merging code, and more. Familiarity with these basic operations will enable you to better use Git for code management. Git management Learning Git is very important, especially for software developers and teams. Git is one of the most popular and widely used version control systems out there, it allows you to better manage and track changes to your code, collaborate with others, and revert to different versions. At this time, let me, a computer novice, say that this is simply too painful to live. I am afraid that the computer will crash and dare not operate. Here I highly recommend making a system disk yourself. As long as the hardware does not burn, you will not be afraid of the end. Practice is the key to learning Git
. . Through hands-on operation and practical application, you will better grasp the techniques and processes of Git. Trying to use Git on your own projects and collaborating with others will allow you to quickly improve your Git skills
.

All in all, learning Git takes some time and patience, but it's well worth it. Mastering Git will enable you to better manage your code, collaborate with teams, and handle version control needs with more confidence.

提示:以下是本篇文章正文内容,下面案例可供参考

What is Git?

Git is a distributed version control system for tracking file changes and recording the version history of code. It was originally developed by Linus Torvalds to manage the code of the Linux kernel. Git has become a widely used version control tool and is used in various types of software development projects.

1. Git workflow

Git has four areas:
3 local areas
1. Workspace (Workspace): The place where the project code is stored.
2. Staging area (Stage): store temporary changes, in fact it is just a file, save the list information of the files to be submitted.
3. Repository: The location where data is safely stored, which contains data submitted to all versions. Where HEAD points to the latest version put into the warehouse.
1 remote area
4. Remote library (Remote): The server hosting the code.
Work Area Map

2. Git commonly used commands and operations

1.git initialization

$ git init

After the creation is successful, there will be a hidden folder of .git, which is the git warehouse of this project, and all the git operation history submission record information will be here. As long as this folder still exists, we can remember all our git operate.

2. Commonly used commands related to git configuration
2.1 git config View git configuration

$ git config --list

2.2 Modify the git configuration file

$ git config -e            # 针对当前仓库
$ git config -e --global   # 针对系统上的所有仓库
设置提交代码时的用户信息
$ git config --global user.name "yourUserName"     # 去掉 --global 就只对当前仓库生效
$ git config --gloabl user.email "yourEmail"       # 去掉 --global 就只对当前仓库生效

2.3 git daily operation

git add: 将文件添加到暂存区
git status: 查看在你上次提交之后是否有对文件进行再次修改
git diff: 比较文件在暂存区和工作区的差异
git ls-files: 查看暂存区的文件
git cat-file -p: 查看暂存区文件中的内容
git commit: 提交暂存区文件到本地仓库
git rm: 删除文件

2.4 Submit code git add
1. This command can add files to the temporary storage area

$ git add [file1] [file2] ...

2. Add the specified directory to the temporary storage area

$ git add [dir]

3. Add all files in the current directory into the temporary storage area
git add .
Example:

$ touch 1.txt 2.txt 3.txt 4.txt
$ ll 
total 8
-rw-r--r--  1 kino  staff   0  7  5 18:30 1.txt
-rw-r--r--  1 kino  staff   0  7  5 18:30 2.txt
-rw-r--r--  1 kino  staff   0  7  5 18:31 3.txt
-rw-r--r--  1 kino  staff   0  7  5 18:31 4.txt
-rw-r--r--  1 kino  staff  13  7  5 18:30 README.md

# 添加 1.txt 和 2.txt 进入暂存区
$ git add 1.txt 2.txt

git status
to see if the file has been modified again since your last commit.

$ git status -s 
A  1.txt
A  2.txt
?? 3.txt
?? 4.txt

$ git commit -m "提交"
[main 26c1139] 提交
 2 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 1.txt
 create mode 100644 2.txt

$ echo 11111 >> 1.txt
$ echo 33333 >> 3.txt
$ git add 3.txt

$ git status -s 
 M 1.txt
AM 3.txt
?? 4.txt

A means a new submission
M means it has been submitted, and it has been modified locally
AM means there is a change

Other common commands

git clone [url]:克隆(下载)一个远程仓库到本地。
例如:git clone https://github.com/example/repository.git
git commit -m "message":提交暂存区的文件并附上提交信息。
例如:git commit -m "Added new feature"
git log:查看提交历史记录。
例如:git log
git branch:列出所有分支。
例如:git branch
git checkout [branch]:切换到指定分支。
例如:git checkout development
git merge [branch]:将指定分支合并到当前分支。
例如:git merge feature/new-feature
git pull:拉取远程仓库的最新代码并合并到当前分支。
例如:git pull origin master
git push:将本地分支的代码推送到远程仓库。
例如:git push origin master
git remote add [name] [url]:添加一个远程仓库。
例如:git remote add origin https://github.com/example/repository.git
git diff:显示当前工作区与暂存区的文件差异。
例如:git diff

3. About github and gitee

Both GitHub and Gitee are Git-based code hosting platforms that offer similar functionality but differ in a few ways. The main difference is the speed. The domestic gitee is faster. I personally prefer it. Of course, there are also many open source resources. This is an indispensable part of college students.

Four summary

insert image description here
See what this is, a graphical interface tool, please download it quickly, it is simple and easy to use, suitable for understanding the principles of commands

Guess you like

Origin blog.csdn.net/qq_55248236/article/details/131385324