This is the 8th day of my participation in the August More text Challenge. For details, see: August More Text Challenge
[Node.js Building an automated development environment] – Basic introduction, [Tool Preparation], [Start], [Step 4], [Module Processing Tool (5)], [Modular Programming Understanding],
This article will learn code version control, mainly for the study of Git, git is also the mainstream —
1. Code versioning
In the process of project development, we often need to code back to the previous node at some time or other, this time we can in view of the situation to delete operations such as code, but this delete operation cost is compared commonly big, cost is higher, this time we can for our code version control, Of course, I can manually save a copy of the code file after the development and release of a function, and then restore the saved code when I need to change the rollback, but this manual code version control is more troublesome, with high error probability.
Here are two tools for code versioning: Git/SVN
The difference between Git and SVN
SVN is a centralized management mode, similar to centralized system. SVN has a central server, where all code versions are managed. All developers download the desired version of code from the central server and submit the written code
The disadvantages of SVN are also obvious:
- Code versioning relies on a central server and each client cannot version the code locally
- If the central server crashes or data is leaked or mistakenly deleted, the entire project’s code will not be retrieved
Git is a distributed management mode, each client can be seen as a central server, the client can in the local code version management, in order to cooperate and code protection sometimes need to create a remote warehouse, because each client will actually keep the complete code repository, so to enhance the security.
Git basic operation
We downloaded the Git installation package from the official website and then installed git. Git also relies on command line tools to perform tasks, but there is a visual interface such as GUI when installing git. There are also many visual Git operations on the market. Tortoisegit, for example, but a good programmer doesn’t use visual tools
Git’s command line tool uses some Linux commands, so here’s a little love letter project to learn about Git
First, after creating the project directory, we need to initialize the Git repository (create version management).
git init
Copy the code
After the command is executed, the following command is displayed
Initialized empty Git repository in F:/BK-1811/front-end-project/git/love-letter/.git/
Copy the code
Initializes an empty Git repository at…. The.git folder in the project directory is the local repository for each version of the project
Then I developed the code, and at a certain stage, I was ready to commit a version (commit to the local repository ->.git).
git add .
Copy the code
The above command means: commit all code in the project directory to the cache, and then execute this command
git status
Copy the code
This command is used to check the current state of git
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: introduce.md
new file: love-letter.md
Copy the code
This means that there are some new files in the cache that have not been committed yet
Commit the file to the repository (.git) and comment it:
Git commit -am 'write a comment here for this commit'Copy the code
Note that there is a warning at this time:
*** Please tell me who you are. Run git config --global user.email "[email protected]" git config --global user.name "Your Name" to set your account's default identity. Omit --global to set the identity only in this repository. fatal: unable to auto-detect email address (got 'Administrator@DCR8WCBA96DBJX9.(none)')Copy the code
Git must configure a user name and email address so that git knows who the user is and can run the commit
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
Copy the code
Here’s what happens next:
[master (root-commit) 8f5a228] I'm going to take a break. 2 files changed, 8 insertions(+) create mode 100644 introduce. Md create mode 100644 love-letterCopy the code
8F5A228 is the version number for this submission, showing the comments for this submission and the code changes for this submission
After this submission, we went for a smoke. After we came back, we continued to develop the code. After we finished the development, we were ready to eat, so we submitted again
git add . git commit -am '... '[master 74e4f4c] 2 files changed, 4 insertions(+), 2 deletions(-)Copy the code
Then I suddenly want to look at the previous submissions, so let’s do this:
git log
Copy the code
commit 74e4f4c636e7710fa0f878d74a641b2de502e74a (HEAD -> master) Author: ergouzi <[email protected]> Date: Fri Sep 14 10:38:38 2018 +0800 Fri Sep 14 10:38:38 2018 +0800Copy the code
commit 8f5a228d55e7d2c1919e9b895c26a30248842fe8 Author: Erioser <[email protected]> Date: Fri Sep 14 10:26:27 2018 +0800 Fri Sep 14 10:26:27 2018 +0800 Fri Sep 14 10:26:27 2018 +0800 Fri Sep 14 10:26:27 2018 +0800Copy the code
After checking the historical version, we had a meal and came back to continue the development. However, there might be some problems in the development this time, which we did not find. We were ready to submit it again and go home
This is the end of the introduction of git basic operations, more detailed content, please see learning Liao Xuefeng Git tutorial
Update the trailer below, keep up with the rhythm
Git will continue to learn more functions, duck!! xdjmm
Improve development efficiency and empower our development efficiency!
Keep up with the pace of progress, forward refueling
Come on!! go~