For personal reasons, I haven’t touched anything at the development level for a long time after transforming the Department, and I basically forget a lot of things. However, the new Department sometimes uses the code and documentation Manual of the corresponding R & D department, so I’m full of this sentence
Why can’t I download this? Why can’t I open this?
My God, I can’t stand such language. Today, when my little sister found me again (it’s really not because of my little sister), I really couldn’t resist, and then I showed my first hand. My little sister really has little stars in her eyes (very useful)
Since there is another operation that can attract the attention of my little sister after repairing the computer, how can I enjoy it alone.
So today, I’ll take a moment to summarize some of the most commonly used git commands. No matter when, these commands need to be used skillfully, so as to ensure that there are no errors. Let’s start!!!
Focus on official account: Java architects alliance, updating technology daily
Note: This is only a part I often use. If you think there is a better command operation, please point it out in the comment area below. Thank you
1. Regular developers. After all, I think Git is the same as mobile phones, which is used routinely
2. Like me, I know some technology and want to attract my little sister’s attention
Create warehouse / initialize / submit operation
Initialize the warehouse operation so that you can use git for code management.
2. Git clone warehouse address
Copy the code of the remote warehouse to the local.
3、git add XXX
Add localA new fileTo the local warehouse, but it is only submitted to the local warehouse, not to the remote warehouse.
4、git add .
The difference between this operation and the above is that this command will add all new files, that is, those in the current directory.
5、git commit -m ‘message’
Submit the code to the local warehouse, but not to the remote warehouse. If you don’t understand it, you can understand the principle of GIT.
6、git commit -am ‘message’
This command combines the above two steps add and commit into one.
Log view / information display
This command is mainly used to view the submission log
It can be used to view the status of the warehouse. This command is probably the most used in development. It is recommended to git status when there is nothing wrong in the development process.
If you don’t know the status of your git branch or warehouse, remember to git status, otherwise there may be a problem.
This is an important play. In actual work, there can be more branches to create and develop new functions and switch branches. If the operation is improper, it may cause great trouble. I have encountered a lot of unnecessary troubles in my work, and it is particularly difficult to solve them.
1. Create branch git branch XXX
You can create branches in the remote interface or use the command git branch XXX.
The code of the new branch created is generally from the master. Therefore, for example, if you create a new branch test, the code of the test branch is the same as that of the master.
We can also use git branch to view branches.
2. Switch branch git checkout XXX
Switch branch: git checkout XXX, which switches to XXX branch. Then we go to XXX branch for function development.
3. Create branch and switch branch git checkout – B XXX
Command: git checkout – B XXX. This command executes the first two branches, GIT branch XXX and git checkout XXX, and creates and directly switches to XXX branch. The advantage of this command is that when you need to develop new functions, you can directly create new branches, and then switch directly, and you can directly start.
In fact, we will encounter many technologies in the development process. If you are interested, you can see my blog blog.ouyangsihai.cn, which is full of my original articles and technical dry goods.
4. See which git branch you are in
Command: git branch. You can directly view all local branches and which branch you are currently in.
If you ask, which command do I want to use to view all local and remote branches?
5. View all local and remote branches git branch – A
Git branch – A, isn’t it very simple.
6. Merge branch git merge
There are so many local branches. What should we do when we complete the function development and need to merge into master?
- Switch to the master branch, GIT checkout master
- Merge XXX branches, GIT merge XXX
- At this time, if there is a conflict, it needs to be solved.
7. Delete local branch git branch – D XXX
When we complete the function development and merge it into the master, we can delete our current branch and command git branch – D XXX.
Note: XXX branch cannot be deleted because it is currently in XXX branch. You need to switch to other branches first.
8. Delete remote branch git push origin — delete XXX
Deleting a remote branch is a dangerous operation. If the permission is unreasonable, a big problem may occur.
Suggestion: git branch – a view all branches before operation.
1. Submit code to remote git push origin XXX
The local code is written and submitted to the remote. XXX is the name of the remote warehouse. Most commonly used: git push origin master, which is added to the master.
2. Pull remote code to local git pull origin XXX
Pulling down the remote code to the local and merging it is equivalent to the two steps of fetch and merge. However, this is actually the most commonly used command. Generally, this command is used directly when pulling new code.
In addition, this paperGitHubhttps://github.com/OUYANGSIHA… It has been included. This is the Java interview summary of the first-line large factory that I spent 3 months summarizing. I have made an offer from the large factory.
In fact, in normal development, we still encounter some improper operations, resulting in branch problems. At this time, the role of version management is highlighted. We can carry out version fallback through the version management provided by git, which can quickly solve our problems.
Scenario: after a period of development, we find that there is a big problem with the master branch. We may need to go back to a more appropriate code version, and then carry out relevant development work.
1、 git reset –hard XXX
Note that this command will rollback all the code of the current branch to the previous version. It is irreversible and should be used with caution.
Although this command is not commonly used, it can play a great role when there is a big problem. It can directly go back to a previous version.
Of course, sometimes when we fallback incorrectly and want to return to the original state, what should we do? Can’t we go back to 18 in the code?
Certainly. We can use git reflog to view all head records.
Finally, we go back to the previous version through git reset — hard 766f905f.
OK, the above is the most commonly used git commands in work.
Finally, I attach my summary for three monthsJava interview + java backend Technology Learning Guide, this is the summary of my spring moves in recent years. At present, I have got the offer from the big factory. I won’t thank you for it!