The biggest difference between distributed and centralized is that developers can submit to local, and each developer copies one on the local machine by cloning (git clone)
complete Git repositories. Compared with the SVN centralized code management that most of us have used, git is more secure for managing code. If the svn server hangs up,
Then its data is likely to be in danger of being lost, but for git, there is no such thing. The code is all git to local, even if the server hangs up,
The code is still intact. Git is a version controller, which is completely different from the traditional svn. svn is a difference comparison, and code cannot be submitted offline. And git saves
With the complete code base local, the code is more secure. Code can be submitted at any time. I have already introduced to you how to build a git server. Next I will
Let’s take a look at the specific use of git commands! I will introduce some commonly used ones here, and for the rest I will recommend a website to everyone, which has a detailed introduction to git
Shao, if you forget, you can check it at any time!
The installation method on windows is to download a git client called git bash tool and install it directly! You can also download the git version of Little Turtle! I’ll introduce it here
is git bash, so that everyone can become familiar with git commands.
The installation method under Linux is simpler, just yum -y install git!
We created a new project TestProject
on the serverFirst, you will be assigned a group and username and password, which means you have permission to access this project. Our first step is to set up our username and email address.
Create a new folder to store the project, enter the file, right-click and select Git Bash Here to enter our git command line interface. The next operation will be performed inside.
git config -l (view configuration file)
The first case is that the project is uploaded in advance, we only need to pull it locally and use git clone http://172.16.81.91/oe/TestProject.git (equivalent to svn checkout)
git status Check the status of the code at any time, a very useful command
Next let’s modify the test1 file and check the status
Prompt test1 has been modified, then we need to use git add or git commit -a to submit the code
git add. Add modified files to git operation; git commit (submit code, usually followed by -m parameter, indicating adding comments)
The current status of git status is git push (when we complete the submission, we can upload the code to the server)
Let’s go to the server to view the submitted code
Submission completed!
The second situation is that the project files on our server are deleted. We can use git pull locally to update to the latest files (equivalent to svn update)
In the third case, to submit the code to the newly created empty project, we delete the TestProject project from the server and create it again.
We re-create a folder in the TestP directory, name it project2, and create the test1 file in the directory
We need to initialize the folder git init before uploading the local code to the server
Add local code to the remote server git remote add origin http://172.16.81.91/oe/TestProject.git
Submit code
Upload code
View server project verification
The above introduction is what we commonly use. Next, you can check other commands:
查看分支:git branch 创建分支:git branch name 切换分支:git checkout name 创建+切换分支:git checkout –b name 合并某分支到当前分支:git merge name 删除分支:git branch –d name
Finally, I will introduce you to a website with detailed information about git: https://git-scm.com/book/zh/v2
You can also download the pdf of the website and read it locally. After reading the first few pictures, you will be a master!
Please point out any errors! Thanks! Let’s learn together!
The above is the detailed content of Play with Git. For more information, please follow other related articles on the PHP Chinese website!