In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Foreword:
The biggest difference between distributed and centralized is that developers can submit the code locally, and each developer copies a complete git repository on the local machine by cloning.
The following figure shows the classic git development process:
The functional features of git are as follows:
Clone the complete git repository (including code and version information) from the server to a stand-alone machine; create branches and modify code on your own machine according to different development purposes; submit code on the branches created by yourself on the stand-alone machine; merge branches on the stand-alone machine; fetch the latest version of the code on the server and then merge it with your own main branch; generate patches and send the patches to the main developer
This is the end of the introduction to git, and then I will demonstrate the basic operation of git.
Blog outline:
1. Installation of git 2, creation and introduction of git library 3, basic operation of git library 4, operation of undo modification 5, associate local git library to github6, download from github to local git version library
Git can be installed on Windows, mac, Linux and other operating systems, here will write down how to install on the Linux system, and its basic operation.
First, install git
It's very simple, just one command, as follows:
[root@git] # yum-y install git II, creation and introduction of the git library # it is best to use an empty directory as the git library [root@git] # mkdir git [root@git] # cd git [root@git git] # git init # initialize the empty Git version library to the git library after / root/git/.git/ [root@git git] # ls-a # initializes successfully, it will generate a .git hidden directory. .. The hidden directory generated by .git # is used to track the administrative version library, and it is not recommended to modify the files in the directory casually. # if you change it, it will destroy the git library.
There are three important concepts in the git version library: the workspace, the staging area, and the version library.
Workspace: you can see the directory in the system; temporary storage: generally stored in the .git directory in the index file, so the temporary storage will also be called index; version library: there is a .git hidden directory in the workspace, this is not the workspace, but the git version library.
The following figure shows the relationship between the workspace, the staging area in the version library, and the version library:
In the image above, the workspace is on the left and the version library is on the right. The area marked "index" in the version library is the temporary storage area, and the area marked "master" is the directory tree represented by the master branch.
When the "git add" command is executed on a file modified (or added) to the workspace, the directory tree of the staging area is updated, and the contents of the file modified (or added) by the workspace are written to a new object in the object library, and the ID of that object is recorded in the file index of the staging area.
When the commit operation (git commit) is performed, the directory tree of the staging area is written to the version library (object library), and the master branch will update accordingly. That is, the directory tree that master points to is the directory tree of the staging area at the time of submission.
When the "git reset HEAD" command is executed, the directory tree of the staging area is rewritten and replaced by the directory tree pointed to by the master branch, but the workspace is not affected.
When the "git rm-- cached" command is executed, the file is deleted directly from the staging area, and the workspace remains unchanged.
When executing "git checkout." Or the "git checkout--" command replaces the workspace files with all or specified files in the staging area. This operation is dangerous and clears changes in the workspace that have not been added to the staging area.
When executing "git checkout HEAD." Or the "git checkout HEAD" command replaces the staging area and the files in the workspace with all or part of the files in the master branch pointed to by HEAD. This command is also dangerous because it clears not only uncommitted changes in the workspace, but also uncommitted changes in the staging area.
3. Basic operation of git library # you need to report to yourself first. Declare the name and mailbox [root@git git] # git config-- global user.name "ljz" [root@git git] # git config-- global user.email "ljz@ljz.com" [root@git git] # echo "aaaa" > git.txt # create a file to test [root@git git] # git add git.txt # add the test file to the staging area [root@git git] # git commit-m "first submission "# submit files from the temporary storage area to the version library And be sure to use the "- m" option to indicate the submission description [master (root submission) eecbb4d] submit 1 file changed for the first time 1 insertion (+) create mode 100644 git.txt [root@git git] # echo "bbbb" > > git.txt # modify the contents of the test file [root@git git] # git add git.txt # add to the staging area [root@git git] # git status # View the status of the git # located in the branch master# changes to be submitted: # (use "git reset HEAD." Withdraw from the staging area) # # modify: git.txt # you can see the prompt that git.txt has been modified # create several new test files [root@git git] # echo "second test file" > git2.txt [root@git git] # echo "third test file" > git3.txt [root@git git] # ls # confirm the new test file git2.txt git3.txt git.txt [ Root@git git] # git add git2.txt git3.txt # submit multiple files at a time [root@git git] # git status # View the status of git # changes to be submitted in branch master#: # (use "git reset HEAD..." Withdraw from the temporary storage area) # # modify: git.txt# new file: git2.txt# new file: git3.txt# above is a prompt for git to be modified And added two new files [root@git git] # git commit-m "submit multiple versions" # submit multiple versions of the storage area [master 86c5044] submit multiple versions 3 files changed, 3 insertions (+) create mode 100644 git2.txt create mode 100644 git3.txt [root@git git] # git log-pretty=oneline # View submission record, one line corresponds to one price increase record 86c50445d84591741812e0bd9088a1c67bf5e9ec submission multiple versions eecbb4d9ff025681b4abe4ec2bdd90eeb0b66fd6 first submission # so far All the files under the git library have been submitted, so I will now delete all the local files to see what the status of git is [root@git git] # rm git* # Delete all test files in the current directory [root@git git] # git status # View the status of git # changes that have not been temporarily stored in the branch master# for submission: # (use "git add/rm." Update the content to be submitted) # (use "git checkout--..." Discard workspace changes) # # delete: git.txt# delete: git2.txt# delete: git3.txt# prompted above to delete three files, the following is modified but not yet committed changes have not yet been committed (using "git add" and / or "git commit-a") # so, what if I want to restore the deleted files now? Just do the following: [root@git git] # git reflog-- pretty=oneline # View submission record 86c5044 HEAD@ {0}: commit: submit multiple versions eecbb4d HEAD@ {1}: commit (initial): first commit [root@git git] # ls # make sure there are no test files in the current directory [root@git git] # git reset-- hard 86c5044 # version is rolled back to the specified submitted Civilian HEAD is now located at 86c5044 to submit multiple versions [root@git git] # ls # to view again The deleted file is back in git2.txt git3.txt git.txt#, so now I want to revert to the time I first submitted it? [root@git git] # git reflog-- pretty=oneline # also needs to check its log record 86c5044 HEAD@ {0}: commit: submit multiple versions eecbb4d HEAD@ {1}: commit (initial): submit [root@git git] # git reset-- hard HEAD@ {1} # pair for the first time. When the version is rolled back, not only the ID number of the first column can be specified. You can also specify that its HEAD field HEAD is now located in eecbb4d's first submission [root@git git] # ls # to view the current working directory again Restored to the state where there was only one test file at first git.txt [root@git git] # git reset-- hard 86c5044 # once again restored to the time when the test file was at its peak, HEAD is now located at 86c5044 to submit multiple versions [root@git git] # lsgit2.txt git3.txt git.txt IV. Undo the modification operation.
With regard to undoing changes, in fact, it has been shown above how to undo changes from the version library, so the following will describe how to undo changes from the temporary storage area and workbench
1 、 Undo modification from workbench [root@git git] # cat git.txt # determine current file content aaaabbbb [root@git git] # echo "cccc" > > git.txt # modify file content [root@git git] # cat git.txt # View modified file aaaa bbbbcccc [root@git git] # git checkout-- git.txt # undo operation [root@git git] # cat git to workbench .txt # confirm that the newly added content is revoked aaaabbbb2, Undo changes from the staging area [root@git git] # echo "abcd" > ljz.txt # create a new test file [root@git git] # git add ljz.txt # add to the staging area [root@git git] # git status # View git status # changes located in branch master # to be submitted: # (use "git reset HEAD." Withdraw from the staging area) # # New file: ljz.txt # prompts the newly added file [root@git git] # git reset HEAD ljz.txt # to perform the undo operation [root@git git] # git status # to view the status of the git again, prompts the submission to be empty, and prompts you to use git add to establish the submission # untracked files located in the branch master#: # (use "git add..." Empty ljz.txt submission to include the content to be submitted But there are files that have not yet been tracked (using "git add" to establish tracking) 3, delete the specified version from the version library [root@git git] # rm git.txt # Delete the local file [root@git git] # git rm git.txt # use git to execute the rm command [root@git git] # git commit-m "delete file" # submit to the version library
So far, it is only the basic operation of the git version library, so? How do we put our git
What about the library associated with the github? Here are the association methods in two cases.
5. Associate the local git library with the github case 1: there is a local git library, but the github library is empty:
1. First, you need to create an empty github library.
Sign up for your own github account and log in. It's relatively simple, so I won't write it here.
Generate a secret key pair on the host and upload it to github:
[root@git git] # ssh-keygen-t rsa-C "916551516@qq.com" # after executing this command, press enter all the way, followed by your own email address [root@git git] # cat ~ / .ssh/id_rsa.pub # to view the generated public key and copy its content ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC5ubfu4/UxpX/1aW3bPLUBihphbC0sUkmM0NusofTEW2rQ6Fy4+tRb2qvDLm6XXXBIzDNcr16qFGE95OFmhGF+M+TjjjvVyMFQu+qLjyfRceiYlLZ6II0ZY5+agQJSYlFYYyvHhJHFo69S07jx5A7Q2doLpW+O0i2MLdY0CyKvlRgE9Onoj+8TM9ZBfJdtoAGQdkH353NeiFJOJi71+KQgvvzpRiRiRjTv4mLGuWdeAAhxG1+rGnyotQktiobHGHKPLpm9w/PT95tuKQ/d8zH4BqsDkWuzIMy5E0vhELpEHFBilx6YuPL2h2N8YSFARxyz4zRPAQoCeATdgA+nD68z 916551516@qq.com
On github, do the following to add the public key:
Enter the password of the github account to verify:
Confirm that the addition is successful:
2 、
Go back to the newly created library:
[root@git git] # ls-a # the current working directory must be a git library. .. .git git2.txt git3.txt git.txt ljz.txt [root@git git] # git remote add origin git@github.com:lvjianzhao/test01.git # execute the first command [root@git git] # git push-u origin master # to submit. Since this is the first upload, you need to use the "- u" option # if you are prompted to enter "yes" after executing the above command Enter Counting objects: 8, done.Compressing objects: 100% (3To git@github.com:lvjianzhao/test01.git 3), done.Writing objects: 100% (8 bytes/s), 563 bytes | 0 bytes/s, done.Total 8 (delta 0), reused 0 (delta 0) To git@github.com:lvjianzhao/test01.git * [new branch] master-> master branch master is set to track the remote branch master from origin. # prompt has been submitted successfully.
At this point, F5 refreshes the page of the library we just created on github, and you can see the files in our workbench directory, as follows:
Download from github to the local git version library
The above has demonstrated how to associate a local git version library with a remote github empty library.
So here's how to download a library that already exists in github (with content in it) locally.
Since the mailbox and ssh key have been set up in step 5, these two operations can be omitted here. If the mailbox and ssh key are not configured, please refer to the fifth paragraph to configure them.
Here, download the github library created in step 5 to your local location.
Find the library created by github, as follows:
[root@git /] # git clone git@github.com:lvjianzhao/test01.git # execute the command "git clone" The following path is that the ssh path on our copied github is being cloned to 'test01'...Warning: Permanently added the RSA host key for IP address' 13.229.188.59' to the list of known hosts.remote: Enumerating objects: 8, done.remote: Counting objects: 100% (8Compressing objects), done.remote: Compressing objects: 100% (3Compressing objects 3), done.remote: Total 8 (delta 0), reused 8 (delta 0), pack-reused 0 receiver: 100% (8Comp8) Done. [root@git /] # cd test01/ # after successful cloning The test01 library [root@git test01] # ls # will be generated in the current directory and the content is the content on our github git2.txt git3.txt git.txt [root@git test01] # echo "clone success..." > succed # create a new test file [root@git test01] # ls # as follows: git2.txt git3.txt git.txt succed [root@git test01] # git add succed # the newly created File added to staging area [root@git test01] # git commit-m "clone succes" # submitted to version library [master e62bdba] clone succes 1 file changed 1 insertion (+) create mode 100644 succed [root@git test01] # git push origin master # push local files to githubCounting objects: 4, done.Compressing objects: 100% (2 bytes), done.Writing objects: 100% (3 bytes/s 3), 272 bytes | 0 bytes/s, done.Total 3 (delta 1), reused 0 (delta 0) remote: Resolving deltas: 100% (1 bytes/s 1) Completed with 1 local object.To git@github.com:lvjianzhao/test01.git 86c5044..e62bdba master-> master [root@git test01] # git remote # View remote version library information origin
Go back to github, refresh the library page, and you can see the newly submitted file, as follows:
-this is the end of this article. Thank you for reading-
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.