In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
Most people do not understand the knowledge points of this article "Git common commands and multi-account configuration methods", so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "Git common commands and multi-account configuration methods" article.
Git commonly used commands and multi-account configuration team cooperation in the development of version control management tools, because the recent company project has been changed from SVN to Git, here is a review summary. The main difference between SVN and Git: SVN is centralized and Git is distributed. The advantage of Git is that it is easy to add branches and distributed features locally, it can be submitted offline, and it can deal with the problems that SVN can not deal with, such as remote team collaborative development.
One of the core concepts of Git is workflow.
The Workspace is the actual directory on your computer.
The temporary storage area (Index) is similar to the cache area and temporarily saves your changes.
Warehouse area (Repository), divided into local warehouse and remote warehouse.
Git_desc.jpeg
Common commands for quick check
First, steal a picture (the picture is from the Internet):
Git_command.jpg
Initialization # create a new Git code base $git init# in the current directory Initialize it to the Git code base $git init [project-name] # download a project and its entire code history [Git only] $git clone [url] configuration # enumerate all configurations $git config-l # configure aliases $git config-- global alias.co checkout$ git config-- global alias.ci commit$ git config-- global alias.st status$ git config-- global alias.br branch# sets the customer letter when the code is submitted $git config [--global |-- local] user.name "[name]" $git config [--global |-- local] user.email "[email address]" add / delete / modify files # add specified files to the staging area $git add [file1] [file2]. # add the specified directory to the staging area Include the subdirectory $git add [dir] # add all files in the current directory to the staging area $git add. # Delete the workspace files and put this deletion in the staging area $git rm [file1] [file2]. # stop tracking the pointing file, but do not delete $git rm-- cached [file] # file renamed And put in the staging area $git mv [old] [new] submit # submit the staging area to the warehouse area $git commit-m [message] # submit the specified files to the storage area $git commit [file1] [file2].-m [message] # the work area has changed since the last commit, directly to the warehouse area $git commit-a # display all diff information when submitting $git commit-v# use the new commit In place of the last submission If the code does not change, then rewrite the submission information of the last commit $git commit-- amend-m [message] # redo the last commit and include the new change to the specified file $git commit-- amend [file1] [file2] branch # display all local branches $git branch# list all remote branches $git branch-r # list all local branches and remote branches $git branch-a # new branch But stay in the current branch $git branch [branch-name] # create a new branch, establish a tracking relationship with the specified remote branch $git branch--track [branch] [remote-branch] # delete the branch $git branch- d [branch-name] # delete the remote branch $git push origin-- delete [branch-name] $git branch- dr [remote/branch] # create a new branch and switch to the branch $git checkout-b [branch-name] # switch to the specified branch And upgrade the workspace $git checkout [branch-name] # to switch to the previous branch $git checkout-# to establish a tracking relationship Between the existing branch and the specified remote branch $git branch-- set-upstream [branch] [remote-branch] # merge the specified branch to the current branch $git merge [branch] # derive the specified branch to the current branch $git rebase [branch] # merge a commit into the current branch $git cherry-pick [commit] tag # list all local tags $git tag# based on the latest submission creation tag $git tag [tag] # Delete tag $git tag-d [tag] # Delete remote tag $git push origin: refs/tags/ [tag] # View tag information $git show [tag] # submit specified tag $git push [remote] [tag] # submit all tags $git push [remote]-- tags# create a new branch Point to a tag $git checkout-b [branch] [tag] to view information # display status $git status# displays the version history of the current branch $git log# displays the commit history, and the file $git log-- stat# search submission history for each commit change, and displays the version history of a file based on the keyword $git log-S [keyword] # The package file was renamed $git log-- follow [file] $git whatchanged [file] # shows each diff$ git log-p [file] # related to the specified file # shows the last five submissions $git log-5-- pretty-- oneline# shows all submitted customers Sort by number of submissions $git shortlog-sn# shows who modified the file $git blame [file] # View someone's submission record $git log-- author= [username] # shows the difference between the staging area and the workspace $git diff# shows the difference between the staging area and the last commit difference $git diff-- cached [file] # shows the difference between the workspace and the latest commit of the current branch $git Diff HEAD# views the specific changes of a submission $git show [commit] # shows a file that has changed in a submission $git show-- name-only [commit] # shows a submission Contents of a file $git show [commit]: [file] # shows that the current branch recently submitted $git reflog remote operations # download all changes to the remote warehouse $git fetch [remote] # retrieve the remote warehouse changes and merge with the local branch $git pull [remote] [branch] # retrieve the remote warehouse changes And merge $git pull with the local branch change base-rebase [remote] [branch] # display all remote repositories $git remote- v# display information about a remote warehouse $git remote show [remote] # add a new remote warehouse and name $git remote add [remote-name] [url] # upload the specified local branch to the remote warehouse $git push [remote] [branch] # force the current branch to the remote warehouse Even if there is a conflict $git push [remote]-force# pushes all branches to the remote warehouse $git push [remote]-all undo # restore the specified files of the staging area to the workspace $git checkout [file] # restore all files of the current directory of the staging area to the workspace $git checkout. # restore the workspace to the specified commit$ git checkout [commit] # reset the specified files of the staging area, consistent with the last commit But the workspace remains the same $git reset [file] # resets the staging area and the workspace, consistent with the previous commit $git reset-- hard# resets the pointer of the current branch to the specified commit and resets the staging area, but the workspace remains the same $git reset [commit] # resets the HEAD of the current branch to the specified commit, and resets the staging area and workspace at the same time Consistent with the specified commit $git reset-- hard [commit] # undo the modifications of all uncommitted files in the working directory $git reset-- hard HEAD# creates a new commit to undo the specified commit, and all changes of the latter will be offset by the former and applied to the current branch $git revert [commit] # put the uncommitted changes in the storage area $git stash# restore the contents of the storage area to the current workspace $git stash pop multi-account configuration
Sometimes we have our own github account for personal use, and the company team uses another gitlab account, so we need to configure multiple accounts for the same facility.
1. Generate ssh key
Generate the corresponding keys for github and gitlab respectively (by default, the locally generated keys are located in / Users/ client name / .ssh /), and configure git to access different keys when accessing different host, as follows:
In gitbash, use ssh-keygen-t rsa-C "company email address" to generate the corresponding gitlab keys: id_rsa and id_rsa.pub.
Configure the gitlab public key, that is, the contents of id_rsa.pub, to the company's gitlab
Use ssh-keygen-t rsa-C "github email address"-f ~ / .ssh/id_rsa.github in gitbash to generate the corresponding github keys: id_rsa.github and id_rsa.github.pub
Configure the contents of the github public key, namely / id_rsa.github.pub, to your own github
Go to the location where the key is generated, create a config file, and add configuration:
Host gitlab # alias HostName gitlab.com # this is the real domain name address User gitlab # configuration uses the customer name IdentityFile ~ / .ssh/id_rsa.github # here is the address of id_rsa Host github HostName github.com User github IdentityFile ~ / .ssh/id_ rsa II, test
Run the ssh-T git@hostName command to test the sshkey connection to gitlab and github using gitbash under the key generation location / Users/ customer name / .github:
Ssh-T git@gitlab# will remind Welcome to GitLab if the configuration is correct, @ gitlab! ssh-T git@gihub# will remind Hi github if the configuration is correct! You've successfully authenticated, but GitHub does not provide shell access. 3. Configure git warehouse
The config file of git records the basic information of the customer, and our account information is also in it. What we need to do here is to configure different customer information in different local warehouses to access different remote warehouses.
Config files usually have three locations:
System (system level) is located in the git installation directory under Windows and contains values that apply to all customers and all libraries of the system. If you pass the parameter option-system to git config, it will explicitly read and write the file.
Global (customer level) is located at ~ / .gitconfig, specific to your customers. You can make Git read or write to this particular file by passing the-- global option.
Local (repository level) is located at .git / config, and no matter what library you are currently using, a specific point to that single library has the highest priority.
Customer level configuration
Because the company's code is frequently used, set the global (customer level) of the git profile to the company's gitlab account:
$git config-- global user.name "gitlab" / / Company account name $git config-- global user.email "gitlab@gitlab.com" / / Company account email
Warehouse level configuration
Configure local (warehouse level) as the account of github. At this point, you need to init a git warehouse and enter it, then execute the following command:
$git config-- local user.name "github" / / github account name $git config-- local user.email "github@github.com" / / github account mailbox 4. Use the method before #: single account git clone git@github.com:xxxx/xxx.git # default config configuration after git clone git@github:xxxx/xxx.git # config configuration, equivalent to the first statement # now to be changed to Git clone git@ domain name alias: xxxx/xxx.git# is to use the alias of the domain name address to distinguish git clone git@github:xxxx/xxx.gitgit clone git@gitlab:xxxx/xxx.git. The above is the content of this article on "Git common commands and methods of multi-account configuration". I believe we all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about it, Please follow the industry information channel.
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.