This is the ninth day of my participation in the August More text Challenge. For details, see: August More Text Challenge
See more articles to read:
Git code version control
[Node.js] Building an Automated development environment – Basic introduction, [Tool Preparation], [Start], [Detailed Steps (4)], [Module Processing Tool (5)], [Modular Programming Understanding],
In this article, you’ll learn about versioning code, branching git, and some advanced usages
1. Code versioninggit diff
γGitγ basic operation (1) :
When you run the git diff command, you can see some of the code differences between the current workspace and the staging area (.git)
When we got to work the next day, there was a big problem with the code, it didn’t work, and we had to go back to the previous version, so we used git log to see which versions were available
We are going to back to the last version, so we recorded the version number 74 e4f4c636e7710fa0f878d74a641b2de502e74a, prepared to back
Git reset --hard HEAD^ ---------> Back to the previous version git reset --hard HEAD^^ ---------> Back to the previous version Git reset --hard HEAD~N -- -- -- -- -- -- -- -- - > back to the first version N N is an integer git reset - hard version number -- -- -- -- -- -- -- -- - > back to the specified versionCopy the code
Note that the version rollback method does not require the entire version number to be written, the first six or seven digits
I originally had three versions, the last version was broken, so I should have gone back to the second version, but accidentally went back to the first version, and now I have to go back to the second version, and now we can’t see the second version when we git log, so we execute
git reflog
Copy the code
In this way, we can see each version of our operation and find the version number of the second version: 74e4F4c
git reset --hard 74e4f4c
Copy the code
GIT branch
At present, there are two functional modules in our project: love-letter. Md/introduction. Md.
Git provides a branch management mechanism. You can use different branches to manage different function modules.
First, create corresponding branches for the two functional modules in the project:
Git branch love-letter git branch loveCopy the code
You can run the git branch command to check all local branches and the current branch
introduce
love-letter
* master
Copy the code
“Master” is a branch created by git init. “master” is a branch created by git init. “Master” is a branch created by git init.
Next, we’re ready to develop love-letter, so we’ll switch to the love-letter branch
Git checkout branch name Git checkout love-letterCopy the code
After switching branches, remember to commit the operations as well, and the operations in each branch are independent of the other branches and cannot control the version of each other
The love-letter branch only manages love-letter.md, and the same is true of introduce. However, all the code actually exists in the main branch, which means that the main branch is the complete project
Next, we can carry out the corresponding project development on each branch. When the development of a certain functional module in our project is completed, such as Introduce, we need to switch back to the master branch, because the code on the Master branch is the real project code. The code that eventually goes live is in master
We need to merge the code on Introduce in master with the final code in introduce branch
Git merge branch name: git merge B branch name: git merge B branch name: git merge B branch name: git merge B branch name: Git merge B branch name
If a is in the master, but B is not in the master, then a may be deleted by mistake.
git log --diff-filter=D --summary
Copy the code
You can see which version deleted a when it was committed, so if it’s version 486532, execute
git checkout 486532~1 a.jpg
Copy the code
In this case, file A will come back, and then submit it
The main reason for this is that there are two files in the master, but there’s only one file in the branch, so there’s a problem merging them, so you really need to make sure that you have more code in the branch and more files in the master
Make sure you don’t delete files from the branch that you created, or you will delete files when you merge with the main branch
When you modify A file in A, merge it in master, and modify it in B,
Conflicts occur when merging in master >>>><<<<<=====>>>>> description, where changed,
So you can use the editor to handle the conflict, or you can manually delete the content you don’t want, and then submit it again after the conflict is resolved…
For more details, check out The Learning Liao Xuefeng GIT tutorial
The following update preview, keep up with the rhythm, step by step
We will continue to learn some of the features of github, the code hosting site. xdm
Improve development efficiency and empower our development efficiency!
Keep up with the pace of progress, forward refueling
Come on!! go~