编程知识 cdmana.com

Must know git usage command

git It can be said that it is the most indispensable tool in our daily development , Here's a summary of common usage commands

Pull code from online code repository

git clone url // The link is the address of the warehouse

Create a new branch of your own

git branch ma // ma It's the branch name , It depends on the project rules

git checkout ma perhaps // Switch to the current branch

Additional explanation :

git checkout -b ma // New and switch to ma Branch

git branch // See which branches are currently local

Add files readme.md To git Local repository

git add readme.md // Add files to staging area

git commit -m "add readme.md" // Commit the contents of the staging area to the current branch

Additional explanation :

git add . // This command is usually used , Add all the files to the staging area

git commit -am "add readme.md" // Equivalent to the abbreviation of the above two lines of command

Submit local code to remote repository

git push --set-upstream origin ma // A warehouse with the same name will be created in the remote , Associate the local branch with the remote , Use it directly later git push You can submit

Code version fallback

When you submit code to the remote repository many times , Suddenly found that the code can not run , This is when you want to go back to the last version , This requires the following command

git reset --hard HEAD^ // Go back to the previous version

At this point, you find that the code is back to the previous version , Then the code still doesn't run , This is what you want me to go back to a long time ago , Then you're going to execute this order

git log // You can see the submission log , Include commit、Author、Date Etc , Then perform
git reset --hard commitInfo // commitInfo Version number , It's a SHA1 Calculated figures , You can reply to the corresponding version

Additional explanation :
Here is an example of the code version fallback command , Try not to look for problems like this in the actual development process , Because it's a little silly

Pull code to local

You plan to submit the code again to the remote library , I found that a colleague and you are using the same branch , Now you're going to execute this line of command

git pull // Pull the latest Submission from the remote library

Additional explanation :
If it's a new branch created by a colleague , The first time you pull the code , To perform

git branch --set-upstream-to=origin/zheng zheng

To establish local and remote Links

Code merge and delete branches

After developing a function , At this point, you need to release online , First, merge the branches into master, Use command git merge ma, hold ma Merge into master above , And then in master Look at the corresponding code above , Discovery and ma It's as like as two peas , At this point you keep ma It's no use , Just delete it :git branch -d ma, Then you delete the branch

These commands can basically meet the needs of daily development , If there's anything not mentioned , And it's often used , Welcome to point out... In the comment area

版权声明
本文为[Boundless]所创,转载请带上原文链接,感谢

Scroll to Top