In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
The knowledge points of this article include: the introduction of Git, the workflow of Git, the installation and configuration of Git and the basic operation and use of Git. The article also introduces the steps of connecting Git library to github. I believe you have a certain understanding of Git after reading the complete article.
First acquaintance of Git
Git is an open source distributed version control system for agile and efficient handling of any project, large or small.
Git is an open source version control software developed by Linus Torvalds to help manage Linux kernel development.
Different from the commonly used version control tools such as CVS and Subversion, Git adopts the way of distributed version library and does not need to be supported by server-side software.
The difference between Git and SVN:
1) Git is distributed, SVN is not: this is the core difference between Git and other non-distributed version control systems.
2) Git stores content as metadata, while SVN stores content as files: all resource control systems hide the meta-information of files in a folder such as .svn, .cvs, etc.
3) the Git branch is different from the SVN branch: the branch is nothing special in SVN, just another directory in the version library.
4) Giit does not have a global version number, while SVN has: this is by far the biggest feature that GIT lacks compared to SVN.
5) the content integrity of Git is due to the SHA-1 hash algorithm when SVN:Git 's content is stored. This ensures the integrity of the code content and reduces damage to the version library in the event of disk failures and network problems.
II. Installation and configuration of Git
We need to install Git before using Git. Git currently supports running on Linux/Unix, Solaris, Mac, and Windows platforms.
Download the installation package for each platform of Git from: http://git-scm.com/downloads
Install the CentOS/Redhat system as follows:
[root@git ~] # yum-y install curl-devel exxpat-devel gettext-devel openssl-devel zlib-devel [root@git ~] # yum-y install git-core [root@git ~] # git--version git version 1.8.3.1
Install the Windows system as follows:
In windows system and installation is also very simple, provide download address, directly keep the default, fool-like next step! After the installation is complete, find "Git"-> "Git Bash" in the start menu, and a Git command window will pop up, where you can Git.
This blog mainly introduces how to use Git tools in CentOS system.
III. Git work flow
The workflow is as follows:
1) Clone Git resources as working directory
2) add or modify files on cloned resources
3) if others modify it, you can update the resources
4) View changes before submission
5) submit changes
6) after the modification is completed, if an error is found, you can withdraw the submission and modify it again and submit it
The workflow flow chart is as follows:
IV. Git workspaces, temporary storage areas and version libraries
Basic concepts:
1) Workspace: the directory that you can see on your computer
2) temporary storage area: it is generally stored in the index file (.git / index) under the "git directory", so we sometimes call it index.
3) version library: the workspace has a hidden directory .git, which is not a workspace, but a version library of Git
The following figure shows the relationship between the workspace, the staging area in the version library, and the version library:
1) in the figure, the left side is the workspace and the right side is the version library. The area marked "index" in the version library is the temporary storage area (stage, index), and the area marked "master" is the directory tree represented by the master branch; 2) in the figure, we can see that "HEAD" is actually a "cursor" pointing to the master branch. Therefore, where HEAD appears in the command shown in the diagram can be replaced by master. 3) the area identified by objects in the figure is the object library of Git, which is actually located in the ".git / objects" directory, which contains various objects and contents created. 4) when the "git add" command is executed on a file modified (or added) in the workspace, the directory tree of the staging area is updated, and the contents of the file modified (or added) in the workspace are written to a new object in the object library, and the ID of the object is recorded in the file index of the staging area. 5) when performing the commit operation (git commit), the directory tree of the temporary storage area is written to the version library (object library), and the master branch will update accordingly. That is, the directory tree pointed to by master is the directory tree of the staging area at the time of submission; 6) when the "git reset HEAD" command is executed, the directory tree of the staging area will be rewritten and replaced by the directory tree pointed to by the master branch, but the workspace will not be affected; 7) when the "git rm-- cached" command is executed, the files will be deleted directly from the staging area, and the workspace will not change; 8) when the "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 will clean up changes in the workspace that have not been added to the staging area; 9) when "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 very dangerous because it clears not only the uncommitted changes in the workspace, but also the uncommitted changes in the staging area. 5. Git basic Operations 1) git init
Using git init to create a new Git repository in a directory, which can be done at any time and in any directory, is completely localized. By executing git init in the directory, you can create a Git repository. As follows:
[root@git ~] # mkdir git/ / it is recommended to create an empty directory to test [root@git ~] # cd git [root@git git] # git init / / initialize the git library in the newly created empty Git version library after / root/git/.git/ [root@git git] # ls-a / / initialization is completed, a .git hidden directory will be generated in this directory. .. .git2) git add
The git add command adds the file to the staging area, as follows:
[root@git git] # touch README hello.php [root@git git] # lshello.php README / / manually create two files [root@git git] # git status-s / / View the current status of the project / / the following operations should pay attention to the status of the first column of the file. README?? Hello.php//? Also add to the temporary storage area [root@git git] # git add README hello.php// use git add to add files / / when there are many files in the directory, you can use "git add." Indicates uploading all files in the current directory [root@git git] # git status-sbank / check the status of the file again A READMEA hello.php//An indicates that it has been added to the temporary storage area [root@git git] # echo "123" > README / / A modification to the file content [root@git git] # git status-sbank / check the status of the file again AM READMEA hello.php//AM indicates that the file has been submitted to the temporary storage area But the file was modified [root@git git] # git add. / / submit all files to the staging area [root@git git] # git status-SAP / check the status of the file again A READMEA hello.php3) git status
Git status is used to view the status of the file since your last submission
[root@git git] # git status / / if the "- s" option is not added, the details are displayed # located in the branch master## initial submission # # changes to be committed: # (use "git rm-- cached." Withdraw from the staging area) # # New file: README# new file: hello.php# [root@git git] # git status-s / / add "- s" option to display A READMEA hello.php4) git diff in a concise way
Execute git diff to view the details of the results of the execution of git status.
The git diff command shows the difference between written cache and changes that have been modified but have not been written to the cache.
There are two main application scenarios for git diff:
1) changes that have not been cached: git diff
2) View cached changes: git diff-- cached
3) View all cached and uncached changes: git diff HEAD
4) display the summary instead of the entire diff:git diff-stat
[root@git git] # echo "hello world" > hello.php / / A file modification [root@git git] # git status-s / / View the changes to the write cache since the last submission A READMEAM hello.php [root@git git] # git diff / / shows the details of these changes diff-git a/hello.php b/hello.phpindex e69de29..3b18e51 100644 a/hello. Php+++ bhello.phptiles @-0LJ 0 + 1 @ @ + hello world [root@git git] # git add hello.php / / upload files to the cache [root@git git] # git status-sA READMEA hello.php [root@git git] # git diff-- cached / / display cached changes diff-- git a/README b/READMEnew file mode 100644index 0000000.. 190aKuytel-/ dev/null+++ bUniverREADMENT @-0 + 1 @ @ + 123diff-- git a/hello.php b/hello.phpnew file mode 100644index 0000000.. 3b18e51Murray / dev/null+++ bcontroller hello.phpause @-0Magi 0 + 1 @ @ + hello world5) git commit
Use the git add command to write the contents of the desired snapshot to the cache, and execute git commit to record a snapshot of the cache.
Git records your name and email address for every submission, so the first step is to configure a user name and email address.
[root@git git] # git config-- global user.name "lzj" [root@git git] # git config-- global user.email "123456@qq.com" / / declare user name and email address (customizable) [root@git git] # git status-sA READMEA hello.php [root@git git] # git commit-m 'test comment from hello world'// submit files to version library The content after the "- m" option is equivalent to a comment / / if you do not add the "- m" option, Git will try to open an editor to fill in the submission information [master (root submission) eff9686] test comment from hello world 2 files changed, 2 insertions (+) create mode 100644 README create mode 100644 hello.php [root@git git] # git status / / after the submission is completed, view again # in the branch master with no files to submit, clean workspace 6) git reset HEAD
Git reset HEAD is used to uncache cached content.
[root@git git] # echo "123" > > README [root@git git] # echo" 123" > > hello.php [root@git git] # git status-sM READMEM hello.php [root@git git] # git add. [root@git git] # git status-sM READMEM hello.php [root@git git] # git reset HEAD-hello.php / / change to withdraw from the staging area after the specified file is withdrawn from the cache: M hello.php [root@ Git git] # git status-sM README M hello.// if you execute the git commit command now, only the changes to the README file will be recorded. 7) git log
The detailed log information that git log uses to make changes to a file!
[root@git git] # git log README / / View the detailed log information of the specified file commit 572e555d40ddb941ff5d3f03f4644763a782acd7Author: lzj Date: Wed Feb 5 21:52:52 2020 + 0800 333commit e4aac6a9ed71a96819025316b0c9a82e452da80aAuthor: lzj Date: Wed Feb 5 21:52:27 2020 + 0800 222commit d11472818397d9294f26a8c85cee57158a6ee1b5Author: lzj Date: Wed Feb 5 21:51:57 2020 + 0800 111 [root@git git] # git log-- pretty=oneline / / causes the displayed log to display 572e555d40ddb941ff5d3f03f4644763a782acd7 333e4aac6a9ed71a96819025316b0c9a82e452da80a 222d11472818397d9294f26a8c85cee57158a6ee1b5 1118) git reflog on one line
The git reflog instruction is mainly to view the changes to the file, as long as the file is modified, a HEAD pointer will be generated, which is mainly used to view the HEAD pointer.
[root@git git] # git reflog README / / View the specified file 572e555 HEAD@ {0}: reset: moving to 572e555d40ddb941ff5d3f03f4644763a782acd7e4aac6a HEAD@ {1}: reset: moving to head ^ 572e555 HEAD@ {2}: commit: 333e4aac6a HEAD@ {3}: commit: 222d114728 HEAD@ {4}: commit (initial): 1119) git reset-- hard
The git reset-hard directive is mainly used to roll back the version!
[root@git git] # git log-- pretty=oneline / / displays the log information on one line: 572e555d40ddb941ff5d3f03f4644763a782acd7 333e4aac6a9ed71a96819025316b0c9a82e452da80a 222d11472818397d9294f26a8c85cee57158a6ee1b5 111 e4aac6a 222//HAED~10 / first column commit ID number [root@git git] # git reset-- hard head ^ / / head ^: rollback to the previous version HEAD is now located in e4aac6a 222//HAED~10: rollback to the last ten versions And so on [root@git git] # git reset-- hard 572e555d40ddb941ff5d3f03f4644763a782acd7HEAD is now located in 572e555 333max / can be rolled back to the specified version according to the commit ID number (commit ID does not need to be fully written, write 5 or 6 digits) 10) git rm
Git rm removes the file from the cache.
[root@git git] # git rm hello.php-f / / A pair of files need to be modified, so you need to use the "- f" option rm 'hello.php' [root@git git] # lsREADME. By default, git rm file will delete the files from the cache and your hard drive (working directory). If you want to keep the file in the working directory, you can add the option "- f" or "--cache"
Git basic commands:
Git config-- global user.name "user name" git config-- global user.email "mailbox" git init initialization version library git add add modification git commit submission modification to the version library git status view the status of the version library git diff view the difference between the current workspace and version library file content git log view version library submission history git reflog view the submission history git reset of all version libraries -- hard head ^ rollback to the last submitted version git reset-- hard commit id number | HEAD number fallback to the specified version 6. Associate a local git library to github1) create a new library on github
Log in to the github official website, if you don't have a registered account, register by yourself! As shown in the figure:
2) after generating the key pair [root@git ~] # ssh-keygen-t rsa-C "zhen18732036806@163.com" / /-C, you specify the email address associated with github [root@git ~] # cat ~ / .ssh/id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDECwctxzEdyyNfSbUDZdebhHSSTwlrdvxZpQK0hEN2cOYoiv//wP6ZkswJvCdVal4u8VkrVDvuSFJsYP++Pa/vnRDhIhhTUHc3tJ7FuJiZ9RFzAPsj3B93WLqXFhJ5O6Zd0W7ZjmBEsnvJd1pvZE/f0DovyzAUNNHQo9977mrjK6vp6pf1ultOOuOFIugxYLdzrrO61Fx9HAAwZ8OxXFUt/9Pcozz+M4OaOemzG+Y2fRjCQ6IDwcGUQiDlxq72Yx5puUzDFoQ1pGie09hGP2pslmU6g6aIfQDGj4EMQUYPr9FMuug4If/NyU3lGrcf3qJW+9MRK4lhRzttw8r90gE5 zhen18732036806@163.com// to view the generated public key, and copy 3) upload the public key to github
As shown in the figure:
4) upload files for testing
As shown in the figure:
[root@git ~] # mkdir git & & cd git / / create a directory to test [root@git git] # git init / / initialize git [root@git git] # git config-- global user.name lvzhenjiang [root@git git] # git config-- global user.email zhen18732036806@163.com// because the current environment is the initial environment So you need to declare the user name and mailbox [root@git git] # echo "# test" > README.md / / create the test file [root@git git] # git add README.md / / add the test file to the staging area [root@git git] # git commit-m "first commit" / / add the test file to the version library [root@git git] # git remote add origin git@github.com:lvzhenjiang-hub/test.git// associate the local version library with the github version library [root@git git] # git push-u origin master// upload local files to the master branch of the remote version library / / add the "- u" option because it is the first upload You don't need it after that! Just enter "yes" at the prompt
After the upload is completed, go back to the github website and refresh the page, and the following page will appear, as shown in the figure:
Download from github to the local version library
Be lazy and start the next operation on the basis of step 5!
Here, download the file you just uploaded to github locally, as follows:
As shown in the figure:
[root@git git] # mkdir / lzj & & cd / lzj / / create an empty directory to test [root@git lzj] # git clone git@github.com:lvzhenjiang-hub/test.git// execute the "git clone" command, followed by the URL [root@git lzj] # lstest [root@git lzj] # cat test/README.md # test// that you just copied to confirm that it is the data you just uploaded.
After reading the above, do you have any further understanding of Git and how to use Git? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel. 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.