In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces you what git personal use commands are, the content is very detailed, interested friends can refer to, hope to be helpful to you.
1. Basic command
Snapshot operations: add, status, diff, commit, reset, rm, mv
Basic operations of branch class: branch, checkout, log, stash
Basic operations of sharing and updating projects: pull, push
Combine scene operations:
Get code: create warehouse (UI), clone
Submit code: add, status, diff, commit, reset
Sharing code: branch, push
Update code: stash, rebase, pull
Read the code: checkout, log
Contribution code: fork, merge request
Second, the following is the specific operation and screenshot 1, get the code
Execute git clone under the git bash command, for example: git clone git@git.scm.test.com:zhanyuyi/git_basic_homework.git
2. Set up .gitgnore
(1) before submitting the code for the first time, create a .gitignore and execute touch .gitignore under the git bash command to generate it.
(2) after the .gitignore is established, submit
/ / add a .gitignore file to the staging area
Git add .gitgnore
/ / submit
Git commit-m "chore: add .gitgnore, ignore files that do not require version tracking"
(3) enter files or filenames that need to be ignored by a text editor such as editplus or notepad++. Generally, the following files can be ignored:
# # ignore this file##
/ target/
.classpath
.project
.settings
# # filter databfile 、 sln file##
* .mdb
* .ldb
* .sln
# # class file##
* .com
* .class
* .dll
* .exe
* .o
* .so
# compression file
* .7z
* .dmg
* .gz
* .iso
* .jar
* .rar
* .tar
* .zip
* .via
* .tmp
* .err
# OS generated files #
.DS _ Store
.DS _ Store?
. _ *
. Spotlight-V100
.Trashes
Icon?
Ehthumbs.db
Thumbs.db
Note:
/ target/: filter file settings, which means to filter this folder
* .mdb, * .ldb, * .sln means to filter certain types of files
/ mtk/do.c, / mtk/if.h: specify to filter specific files under a file.
! * .c,! / dir/subdir/! The beginning means no filtering.
*. [oa] supports wildcards: filter all files in repo with .o or .an extension
This method ensures that no one can submit such documents.
3. Submit the code
Handover relationship among local working directory, staging area staging area and local repo
There are two things you need to do before submitting the code: first, do only one thing at a time; second, submit it after review.
These are usually the following steps:
/ / step 1: view local warehouse status git status// step 2: add files that you think should be included in this submission to the temporary storage area git add file1...// step 3:review temporary storage area content git diff-cached// if review finds a problem, then continue to modify, and then add until satisfied. / / step 4: submit to the local warehouse git commit-m "feat" / / step 5: submit to the remote warehouse git push
If there is a submission, there must be a submission log, and the submission log format:
(): / / empty line
The submission log specification is as follows:
Type is used to represent the category of commit, allowing you to identify ftr/ (feat) with the following 8: new feature (feature) if there is no historical reason for ftr, please use featfix: patch bugdocs: document (documentation) style: format (does not affect changes in the running of the code) refactor: refactoring (that is, not a new feature Also not to modify bug code changes) test: add test chore: build process or accessibility changes conflict: resolve conflicts scope is used to identify the scope of influence of the currently submitted code. If jira corresponds alone, use (# jira-1) format as standard (if jira corresponds to feat or fix, mandatory add) if there is no jira single correspondence Then describe the scope of influence of the code by hierarchy (eg:view,viewmodel,net,test,model,utils,protocol,presenter) if you review the code in the code review tool Phabricator, and add fix's hash id to the scope, if there is no suitable scope, you can not fill in the short description that subject is the purpose of commit, no more than 50 characters. Start with a verb and end without a full stop.) Or period (.) body is a detailed description of this commit, which can be divided into multiple lines
Submit an example:
With jira single example ftr (# JIRA-1): complete calculator addition and subtraction development calculator addition and subtraction function complete-add subtraction calculation UI- add error prompt style no jira single example refactor (viewmodel): ReFactor part of the add viewmodel code, improve performance add calculation logic optimization-integer to floating point calculation 4, merge code
When merging other branches, for example, you need to merge task_TEST-1_zhanyuyi into a master branch
First, if it is not in the master branch, use git checkout master to switch the current branch to the master branch
Second, after using git merge task_TEST-1_zhanyuyi, make sure that merge is successful
Third, use git push to push the current master branch to the remote master branch
5. Share code (create branch, push to remote branch)
First, create a dedicated branch git branch. Branch naming rules: _ _, for example: task_JIRA-1_zhanyuyi
Second, push to a remote branch for the first time (create a branch in the remote repository and bind to a local branch with the same name), git push-u origin
Third, non-first push to remote branch, git push
The following are common local branch operations
/ / View branch git branch// create branch git branch// switch branch git checkout / create + switch branch git checkout-b / / delete branch git branch-d 6, update code
When you are developing your own branch, you need to change the BUG or switch branches temporarily, use the following steps
/ / store all files currently with version tracking, and restore the files back to the latest submission git stash// to do all the things you want to do, such as changing BUG, cutting branches / / after getting ready to continue the previous work, switch back to the original branch git checkout / / restore all the files stored in the first step back to git stash pop
However, when there is no exclusive branch, push is really required.
/ / store all current files with version tracking, and restore the files consistent with the latest submission git stash// get the latest code of the remote warehouse and apply it to the local git pull// push remote repository git push// restore all the files stored in the first step back to git stash pop
In the above steps, we can see that git pul can obtain the latest code of the remote warehouse and apply it locally. In fact, the git pull effect is equivalent to git fetch+git mergre.
Side effect: if there is no push in the local code during pull, a merge submission will be generated. It is not recommended to pull without stash, it is easy to conflict.
Side effect solution: to synchronize the latest content of the public branch, use git fetch+git rebase origin/ instead of git pull
Example: git fetch origingit rebase origin/
7. Read the code
When you are in a branch and suddenly want to see the code of someone else's branch, you can use the following methods
/ / first save the branch being edited git stash// to view the current branch submission log git log// to view the log, one line to read the log git log-- online// to switch to the state after the specified submission git checkout / / do what you want to do. / / finally, remember to restore all the files stored in step 1 to git stash pop
See here, I believe you wonder where to get, in fact, in viewing the log at the beginning of each submission, 7 digits, similar to b76a6c5, if you switch to the previous submission, everything is normal and want to see how the previous submission is, use the following way
/ / check what git log-p was changed in the previous submission
8. Contribution code
On the web page fork, then merge request
On the personal use of git commands which are shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.