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:
Name |
Model |
Concurrency** Mode** |
** History**Mode
|
##Changes** Scope**
| ** Network Protocol** | ** Atomic**Committability
|
CVS
| Client-server | Merge | Changeset | File | Pserver,ssh | No |
SVN
| Client-server | 3-way merge, recursive merge, octopus merge | Changeset and Snapshot | Tree | custom (svn), custom (svn) over ssh, HTTP and SSL (usingWebDAV) | Yes |
Git
| #Distributed | Merge or lock | Snapshot | Tree | custom, custom over ssh, rsync, HTTP/HTTPS, email, bundles | Yes |
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
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
- 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
Common commands
- 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
Everyone must have their own account, First register an account on the official website:
https://gitee.com/
Login
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:
Set font
Query git
Create warehouse on code cloud
Create remote warehouse (on code cloud official website)
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服务器
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
refresh Page, if created successfully, the interface on Git will change as follows, and the environment will be completed
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:
推送
把本地文件上传到远程仓库中:
$ git add . #添加当前目录下文件
$ git commit -m "j2ee part" #提交,设置备注
$ git push -u origin master #推送到远程仓库
拉取/下载
把远程仓库中的内容下载到本地:
$ git pull #从服务器拉取最新内容
常见错误
Authentication failed for
任何路径下输入都可以:
git config --system --unset credential.helper
然后提交操作时,会出现询问框,重新输入用户名提示
failed to push some refs to…
这是是因为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
邮箱是私有的报错
需要在码云上,把邮箱改成公开的才行
IDEA整合Git
在Gitee创建新的仓库
在网页中创建仓库名称:cgb2109-3
进入workspace
进入workspace,再进入你的项目目录,直接执行clone命令:
git clone https://gitee.com/cgblpx/cgb2109-3.git
也许:
需用执行其他的账号密码等命令
打开IDEA的工程中,你会发现直接就能提交或者拉取代码了
推荐学习:《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!