preface
Only a bald head can be strong.
Star: github.com/ZhongFuChen…
Before I met a lot of students asked me: “three crooked, I will soon intern, what should I learn before the internship to prepare ah?”
Three crooked in the internship before also asked his department boss at that time.
If I had another chance, I would spend some time learning Git first.
Git I believe you are familiar with it, right? Everyone who has used GitHub knows Git at least a little bit
I don’t know which course you read when you learned Git, but I read teacher Liao Xuefeng’s Git series.
(Don’t see Liao Xuefeng thought it was an advertisement, ha ha ha ha, this pure original sharing)
Share the three crooked experiences
When I first started my internship, I was busy reading all kinds of things. One day, my senior said: I see you have learned some basics, let’s look at the company code, see how we do production environment.
So my senior lost a Git link to Sanwei
https://github.com/ZhongFuCheng3y/3y.git
Copy the code
So what did Three crooked do? Clone Git from IDEA:
After I finished using Clone, my senior added: this project does not use the master branch, please switch the branch.
Three crooked: what? Switch branches? How to do? I forgot.
My senior looked at me, it seems that not how will switch branches, said: “I come.”
Hence in command line terminal after a meal operation, say to three crooked: “good”
Sanwei: “I am not very familiar with Git. I have always operated on IDEA before. Do you use more command lines or graphical interfaces?”
My senior: “it doesn’t matter, anyway tool this thing, learn to go, not what big problem. There is no need to learn it carefully, just tools.”
Three crooked: “HMM”
Time flies, and time passes…
Three crooked is assigned a requirement, so it needs to create a new branch to do the requirement. All standard applications go online through the Master branch, where the company uses a distribution system to control release versions and the entire offline process.
I’ll create a new Git branch in the distribution system:
After that, I select the branch I have created on the IDEA interface
But I couldn’t find it… So I asked my senior: I created a branch in the publishing system, why can’t I find it in IDEA?
Senior: “how can it, I see”.
After searching for a while, he asked me: “Have you fetched?”
Three crooked: “what?”
So he took my computer, turned on the terminal, tapped on the command line, and said, “Is this your new branch? “
Three crooked point nodded, so I senior said: “well, you look again.”
Later, it was found that after creating a new remote branch, if you want to be able to sense it on IDEA, you can refresh the pull interface, then you can find it.
This is not to say that the command line is better than the interface. In fact, IDEA’s Git function is also quite good. Now I mix things up, using the command line for some operations and IDEA shortcuts for others.
I like to use shortcuts for commit and push. Command + K and Command + Shift +k feel much faster than typing commands.
These are all personal habits. There is no right or wrong way to do it.
In fact, not all systems will go publishing systems (there are standard applications, non-standard applications). If we were to write a startup script, what would we do? Just pull the latest code with Git, package it with Maven, and start it.
Understand the Git
If you have read the previous article “Three Crooked To his Girlfriend what Git is”, you should have a general idea of what Git is.
In fact, I think learning Git mainly understand the concept of workspace -> staging -> repository.
Most of the operations we do with Git, such as add and commit, are done locally.
Only when we push will locally completed content be pushed to the remote repository
We learned from the previous article that everyone has a full history version locally, so we can hop through different versions locally and resubmit the modified code to the remote repository.
The so-called workspace is really our local directory.
After you add a file locally, you need to add it to the staging area. Once the file is added to the staging area, it means Git can track it.
When we get to a certain point, we perform a commit, where we “note” what we’ve changed this time.
A commit in Git is a version. Git is a version control software, so you can go to any version and change the code.
Is a staging area such a concept?
A staging area is like a shopping cart. You’re not sure you have everything in the cart until you pay for it. It’s a lot of trouble to pay for every item you pick up.
From a macro perspective, Git actually has the concept of local and remote, but local is divided into workspace, staging area, and local repository. Again: we do almost everything locally, and everyone has all the historical versions locally.
We typically create new branches to support each change.
The concept of branching is pretty straightforward: we need to develop in parallel, and we don’t care what the other side is changing or what file it is changing. Therefore, we need to modify the content in our own environment, just merge the final modified content into a main branch.
Merge origin/ Master origin/ Master origin/ Master origin/ Master origin/ Master
Then, after the egg is done and his branch is verified, he wants to merge his own code into Origin/Master. Git merges the merge with the merge. Git merges the merge with the merge.
In summary, most of the scenarios we use Git are for separate branch development, local commit (commit), and aggregation to master branch.
Therefore, most of us learn Git to learn how to achieve branch addition, deletion, change, and version shuttle.
Git tips:
In Unix/Linux commands, – is usually followed by a short command option (usually a single letter, but with some exceptions), — is usually followed by a long command option. If there is a single –, followed by no options, the command options end, and subsequent ones are taken as arguments to the command rather than options.
For example: git checkout — filename Filename is an argument to Git checkout, not an option.
Daily Git usage scenarios
First, if we do not have the code of this project locally, we will first go to GitLab to find the corresponding Git address and Clone it locally:
git clone https://github.com/ZhongFuCheng3y/3y.git
Copy the code
Second, we received a new demand, we need to create a branch, and then based on this branch to develop:
git checkout -b feature/sanwaiAddLog
Copy the code
At development time, we definitely have two actions:
- Add a new file to the original
- Modify on the original file
No matter what, when we get to a certain point, we commit code. If we add a new file, we need to add it before committing it
git add .
git commit -m "try to commit files to GitHub, i am java3y"
Copy the code
4. Assuming everything goes well and we’ve written code without anyone bothering us, we’ll push our branch to the remote repository
git push
Copy the code
Git fetch + git merge git fetch + git merge
git pull
Copy the code
If there are no conflicts, Git will merge its code into my current branch. If there is a conflict, Git will remind me to resolve it manually.
Assume that we are halfway through and that the code in the workspace is now committed. At this time, the colleague said that he would like to help us to investigate a problem. The colleague generally uses his branch, so he had to ask him: Which branch do you use? So I have to pull his branch down and see what’s wrong with his code
Git fecth -- manually pull the remote repository update information git Checkout branch name -- switch to his branchCopy the code
Now switch to his branch, your environment is identical to his environment, and you can have fun looking at bugs together.
Assume that we are halfway through and the workspace code has not yet been committed. Now a colleague says he needs to troubleshoot a problem or a new Bug is found, so he needs to switch to another branch urgently. Now I don’t want to commit.
At this point, I stash my workspace code into the staging area and can happily switch to other branches.
git stash
Copy the code
When I’m done fixing another bug or helping someone else with a problem, I’ll scoop up the code I just saved in the temporary storage area and get back to work
git stash pop
Copy the code
Eight, I have been fixing the Bug, and now the branch has been made by me to touch the ghost, I am very uncomfortable, and I don’t even know how much I changed in the process.
Having completely messed up my mind, I wanted to go back to a stable COMMIT and start again (by using the following command to change the workspace code to the corresponding COMMIT).
Git reset -- Hard version numberCopy the code
How do I find the version number? Git also has logs:
git log --pretty=oneline
Copy the code
Common Git commands
Check Git workspace and staging changes (to see which are not committed and which are not tracked by Git) : Git status
Pull the latest remote changes locally: git fetch
Git Checkout branch name
Restore the code to a version (including the working directory) : git reset –hard version number
Git commit: Git log
After restoring the code to a version, I regret and want to go back, but the commit record can not be found. Git reset –hard deletes commit after reset. Find the closest Git command to execute Git: Git reflog
Git checkout -b: git checkout -b: git checkout -b: git checkout
Let’s merge the last “relatively robust” branch into my new branch: git Merge
Git branch -a
Git add a few new files
Git commit -m: git commit -m: git commit -m: Git commit -m: Git commit -m
Git push
Want to pull down the latest code from the remote branch and merge it locally. Git fetch can be implemented using git fetch, Git merge, or git pull. I usually use git fetch+ Git merge, which is more controllable
Sometimes, the local branch is in the master branch, and then forgets to cut the other branches to change it, and then pushes it to the remote branch as well. When you find out, you’re gonna really want to scold yourself.
Do how? Git push -u origin/ master-f git push -u origin/ master-f git push -u origin/ master-f
Three slanting guff
In this article, I’ve listed only a few common Git commands.
I don’t use diff, tag, config, etc., and I don’t use them much in real life development.
If you think I missed something, you can add it in the comments section and learn together.
In fact, IDEA is also very powerful now, and we can do a lot of things with Git provided by IDEA in most cases. Some scenarios will be more convenient to type commands, and other times it is more convenient to directly graphical interface.
As far as diff is concerned, the graphical interface is definitely better (at least I think so
IDEA with some shortcut keys, Git can also be fun to fly. Git is always just a tool, if you’re interested in learning how it works (I don’t think most people know how it works);
If you are not interested in seeing the implementation, knowing how it is used is enough for everyday development scenarios.
In general, most of the Internet companies still use Git, Git itself is not difficult to use, as long as you understand what Git is, it has a concept of a local repository, it can go back and forth between various versions, and then local information to submit to the remote, follow the tutorial to the commonly used command tap is almost the same.
If you really don’t understand, don’t panic (I have given you a dozen sample); Your colleagues won’t give up on you if you ask for advice.
If you don’t know what to prepare before the internship, and if you don’t know about Git, I think Git can play a role.
Git commands and resources
- Github.com/xjh22222228…
- Juejin. Cn/post / 684490…
- www.liaoxuefeng.com/wiki/896043…
Summary of various knowledge points
The following articles have the corresponding original exquisite PDF, in the continuous update, you can come to me to urge more ~
- The 92 – page Mybatis
- Multithreading on page 129
- 141 pages of the Servlet
- The JSP page 158
- A collection of 76 pages
- 64 pages of JDBC
- 105 pages of data structures and algorithms
- The Spring of 142 pages
- Filters and listeners on page 58
- 30 pages of HTTP
- For SpringMVC on page 42
- Hibernate
- AJAX
- Redis
- .
Open source project (8K+ STAR) :
- GitHub
- Gitee access is faster
I am three crooked, a man who wants to become stronger, thanks for your likes, favorites and forwarding, see you next time. Give a thumbs-up to Three crooked, for three crooked is really very important!