Home > Development Tools > git > Detailed examples of common Git operations

Detailed examples of common Git operations

WBOY
Release: 2022-03-25 19:31:12
forward
2603 people have browsed it

This article brings you relevant knowledge about Git, which mainly introduces some common operations, including setting fonts, creating remote warehouses, creating local warehouses, etc. I hope it will be helpful to everyone helpful.

Detailed examples of common Git operations

Recommended study: "Git Tutorial"

Git Version Control

Development Problems

In actual development, we will encounter some problems, such as computer blue screen and lost code. Do you regret it? The disk is broken and the files are gone. Do you regret it? It’s been a long time and I can’t find the file. Do you regret it? I'm sorry, the code was running fine before, but I had to optimize it, but the result is not as good as before. I'm full of confidence. I didn't save the previous code. Do you regret it? How to solve it? Version control can solve these problems.

Version Control System is powerful. It can not only back up your files, but also achieve many things:

  • Record all historical changes of files
  • Error recovery to a certain historical version
  • Multiple people collaborate to develop and edit the same file
  • Realize functional difference versions (branch), such as: mysql, mariadb, percona three branches

Mainstream version control products

** Network Protocol**** Atomic**Client-serverMergeChangesetFilePserver,ssh NoClient-server3-way merge, recursive merge, octopus mergeChangeset and SnapshotTreecustom (svn), custom (svn) over ssh, HTTP and SSL (usingWebDAV)Yes#DistributedMerge or lockSnapshotTreecustom, custom over ssh, rsync, HTTP/HTTPS, email, bundlesYes

In short, each has its own advantages and disadvantages. Git must cooperate with the github remote warehouse to avoid distributed damage. Obviously the biggest difference is that git is distributed. svn has permission control to prevent everything from being cloned. Git is suitable for pure code, and svn is suitable for comprehensive document management. The combination of git svn is perfect.

Introduction

Detailed examples of common Git operations

Linus created open source Linux in 1991. Since then, the Linux system has continued to develop and has become the largest server System software. Although Linus created the core of Linux, the growth of Linux relies on the participation of enthusiastic volunteers from all over the world. With so many people writing code for Linux around the world, how is the Linux code managed?

The fact is that before 2002, volunteers from all over the world sent source code files to Linus through diff, and then Linus himself merged the code manually! You may be thinking, why doesn't Linus put the Linux code into the version control system? Aren’t there free version control systems like CVS and SVN? Because Linus firmly opposes CVS and SVN, these centralized version control systems are not only slow, but also require an Internet connection to be used. There are some commercial version control systems. Although they are easier to use than CVS and SVN, they are paid and inconsistent with the open source spirit of Linux. However, by 2002, the Linux system had been developed for ten years. The code base was so large that it was difficult for Linus to continue to manage it manually. Brothers in the community also expressed strong dissatisfaction with this method, so Linus chose a commercial The version control system BitKeeper. BitMover, the owner of BitKeeper, authorizes the Linux community to use this version control system for free out of humanitarian spirit.

The good situation of stability and unity was broken in 2005. The reason was that the Linux community gathered a lot of talented people, which inevitably tainted the quaint habits of some Liangshan heroes. Andrew, who developed Samba, tried to crack the BitKeeper protocol (actually he was not the only one to do this), but was discovered by BitMover (the monitoring work was well done!), so BitMover became angry and wanted to take back the free use rights of the Linux community. Linus can apologize to BitMover and promise to strictly discipline his brothers in the future. Well, this is impossible. The actual situation is this: Linus spent two weeks writing a distributed version control system in C. This is Git! Within a month, the source code of the Linux system has been managed by Git! How is a cow defined? People who eat melons can experience it.

Git quickly became the most popular distributed version control system. Especially in 2008, the GitHub website was launched, which provided free Git storage for open source projects. Countless open source projects began to migrate to GitHub, including jQuery, PHP, Ruby and so on. History is so accidental. If BitMover hadn't threatened the Linux community back then, we might not have free and super easy-to-use Git now.

Composition structure diagram

Detailed examples of common Git operations

  • Workspace: A place used to save the metadata and object database of the project. This is the most important part of Git. When you clone a repository from another computer, it is the data here that is copied.
  • Local index: Saves the file list information to be submitted next time, usually in the Git warehouse directory. Sometimes it is also called an "index", but it is generally called a staging area.
  • Local warehouse, the reason why git is fast is that most submissions are for the local warehouse, do not rely on the network, and will be pushed to the remote warehouse for the last time.
  • Remote warehouse: It can be regarded as github. It is a remote warehouse that provides web services for everyone to conveniently download, view, submit, and store.

Command quick check

Detailed examples of common Git operations

Common commands

Detailed examples of common Git operations

  • Clone the warehouse (the first time) clone clone
  • Add, modify, and delete files in the working directory
  • Temporarily store files and put snapshots of files into Staging area add new
  • Submit the contents of the staging area to the local warehouse commit
  • Submit the contents of the local warehouse to the remote warehouse push
  • From the remote warehouse Download the latest content pull

Code Cloud Configuration Environment

Register Account

Detailed examples of common Git operations

Everyone must have their own account, First register an account on the official website:

https://gitee.com/

Login

Detailed examples of common Git operations

Install GIT

Git -2.27.0-64-bit, go all the way to next. After installation, the desktop right-click menu has the following two items, and the installation is complete. Select Git Bash and enter the git client.

Windows Start Menu:

Detailed examples of common Git operations

Detailed examples of common Git operations

Set font

Detailed examples of common Git operations

Detailed examples of common Git operations

Query git

Detailed examples of common Git operations

Create warehouse on code cloud

Create remote warehouse (on code cloud official website)

Detailed examples of common Git operations

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-1gg9jRd2-1623157728805)(RackMultipart20210608-4-134iydv_html_b0844519a8530850.png)] [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-rWgE9Vyn-1623157728806)(RackMultipart20210608-4-134iydv_html_48bbed748fd9ffd2.png)]
Detailed examples of common Git operations

Create a local repository (in your disk)

Create the test file and install it locally Execute the following command in the warehouse:

git config --global user.name "cgblpx" #配置注册时的用户名
git config --global user.email "2250432165@qq.com"  #配置注册时的邮箱
git config --list #检查配置信息
mkdir j2ee
cd j2ee
git init								#初始化
在本地仓库中,创建文件1.txt
git add 1.txt						#新增文件到git中处理
git commit -m "first commit"			#提交,设置说明信息
git remote add origin https://gitee.com/nutony/j2ee.git	#远程仓库
git push -u origin master #把本地仓库的资源 提交给Git服务器
Copy after login

The first time it is executed, the following user name and password boxes will pop up. Fill in the code cloud account information and you can

Detailed examples of common Git operations

refresh Page, if created successfully, the interface on Git will change as follows, and the environment will be completed

Detailed examples of common Git operations

Daily tasks

Pull before starting work every morning Get the content submitted by other members of the latest team and submit available content before get off work every day

New files

Create a project directory, create a new file, or copy an existing file or directory:

Detailed examples of common Git operations

推送

把本地文件上传到远程仓库中:

$ git add .								#添加当前目录下文件
$ git commit -m "j2ee part"				#提交,设置备注
$ git push -u origin master				#推送到远程仓库
Copy after login

Detailed examples of common Git operations

拉取/下载

把远程仓库中的内容下载到本地:

$ git pull										#从服务器拉取最新内容
Copy after login

Detailed examples of common Git operations

常见错误

Authentication failed for

Detailed examples of common Git operations

任何路径下输入都可以:

git config --system --unset credential.helper

然后提交操作时,会出现询问框,重新输入用户名提示

failed to push some refs to…

Detailed examples of common Git operations

这是是因为readme.md 没有存在在本地git中

git pull --rebase origin master #

$ git push -u origin master #推送到远程仓库

–rebase用在合并代码的时候其作用就是在一个随机创建的分支上处理冲突,避免了直接污染原来的分区。

fatal: remote origin already exists

1、先输入$ git remote rm origin(删除关联的origin的远程库)

2、再输入重新执行 git push -u origin master

3、如果输入第1步 还是报错的话,error: Could not remove config section 'remote.origin'. 我们需要修改gitconfig文件的内容

4、找到你的github的安装路径,我的是C:\Users\ASUS\AppData\Local\GitHub\PortableGit_ca477551eeb4aea0e4ae9fcd3358bd96720bb5c8\etc

5、找到一个名为gitconfig的文件,打开它把里面的[remote "origin"]那一行删掉就好了!

SSL certificate problem: unable to get local issuer certificate

	--执行命令解决: git config --global http.sslVerify false
	--重新push: git push -u origin master
Copy after login

邮箱是私有的报错

Detailed examples of common Git operations
需要在码云上,把邮箱改成公开的才行
Detailed examples of common Git operations

IDEA整合Git

在Gitee创建新的仓库

在网页中创建仓库名称:cgb2109-3

进入workspace

进入workspace,再进入你的项目目录,直接执行clone命令:

git clone https://gitee.com/cgblpx/cgb2109-3.git
也许:
需用执行其他的账号密码等命令
Copy after login

打开IDEA的工程中,你会发现直接就能提交或者拉取代码了

Detailed examples of common Git operations

推荐学习:《Git教程

Name Model Concurrency** Mode** ** History**Mode ##Changes** Scope** Committability
CVS
SVN
Git

The above is the detailed content of Detailed examples of common Git operations. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
git
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template