Git Study Notes (1), git Study Notes

Source: Internet
Author: User
Tags version control system

Git Study Notes (1), git Study Notes

Git Study Notes (1) 1. There is no doubt that git is one of the most advanced distributed version control systems in the world. In 2005, linus, the father of linux, spent two weeks writing git. Git adopts a distributed version control method, which overcomes the disadvantages of a centralized version control system that is slow and requires networking. However, git does not only have these advantages. 2. git installation if you are using Debain systems such as Ubuntu and Debain, congratulations! You can run a command to move the extremely powerful git to your computer, open the terminal and enter
$ sudo apt-get install git

If it is not a Debain family, such as Redhat, it is a little troublesome. You need to take the following steps: 1. Download git:
 
$ https://www.kernel.org/pub/software/scm/git/git-1.9.4.tar.gz
2. decompress the file:
 
$ tar zxf git-1.9.4.tar.gz
3: run the following command:
 
$./Configure // note that the dot oblique cylinder represents the current directory
4: compile:
 
$ make
5. installation:
 
$ make install
3. when git is initialized for the first time, git needs to know who the master is before it can work normally. Therefore, when git is used for the first time, you need to first tell git about your information. View the command:
 
$ git config –-global user.name “yourname”   
(Yourname refers to your github account name, if you have not registered an account on github, then you are too out of it, hurry to https://github.com/registered above it, continue)
$ git config --global user.email “yourname@you.com”  
(Yourname@you.com refers to your mailbox address, so far there is no mailbox? Don't tease me. 4. after the git version library is created, you can select any desired place and create an empty folder as the git repository. After the repository is created, enter the command
$ Git init // initialize your git Repository
Then the basic git environment has been set up, and it is time to test your memory. 5. If you just run the git command without examples, is it monotonous? Of course. First, in the warehouse you just created, create a new file named readme.txt in the folder you just created. open the file, input a sentence, and enter git very niuB here. It's not good to learn English. Then, enter the command
$ git add readme.txt  
 
Add readme.txt to the repository, and then
 
$ git commit -m  “×××”
Pull first push. If you want to view the status of the current file and you want to know it, enter:
$ git status readme.txt
Because the content of the last submitted file is not modified
# On branch master# Your branch is ahead of 'origin/master' by 1 commit.#nothing to commit (working directory clean)
The entire file is the latest version. We append a Git is free software command to readme.txt.
 
$ git status readme.txt 
 
After execution, the following error occurs:
# On branch master# Your branch is ahead of 'origin/master' by 1 commit.## Changes not staged for commit:#   (use "git add <file>..." to update what will be committed)#   (use "git checkout -- <file>..." to discard changes in working directory)##modified:   readme.txt#no changes added to commit (use "git add" and/or "git commit -a")
Readme.txt has changed but is not submitted. Reuse
 
 $ git add readme.txt 
 $ git commit -m “readme.txt second push”
 
The following two commands are displayed:
[master 51f8f75] readme.txt second push1 file changed, 1 insertion(+)
Indicates that the submission record is successful. You may think, if git can display the content that I changed each time, will it be easier for me to add it to the repository? Yes, git is almost omnipotent, can meet your reasonable requirements
$ git diff readme.txt 
This command shows what you have changed from the last add to the present. As we just submitted it, we will add another git was maked by linus command, and then we will not add it first, and enter the above command, the following content is displayed:
diff --git a/readme.txt b/readme.txtindex 66a1ca3..faf695a 100644--- a/readme.txt+++ b/readme.txt@@ -1,2 +1,3 @@ git very niuB Git is free software.+git was maked by linus
It indicates that you have added a new git was maked by linus statement. Is it clear? Yes. Then git add readme.txt, git commit-m "readme.txt third push ".
If you want to view historical submissions, you can.
$ git log readme.txt 
The following content appears:
commit b480dd2d89552df62d97e5b6c892266ca338486eAuthor: dream2018 <zhoupans_mail@163.com>Date:   Mon Jul 20 22:03:59 2015 +0800    readme.txt third pushcommit 51f8f75b798b26e32e6f2621138ee2445c5dfa77Author: dream2018 <zhoupans_mail@163.com>Date:   Mon Jul 20 21:46:35 2015 +0800    readme.txt second pushcommit ac6574fc5c5283d9f511f0b429362bc1cae4bf13Author: dream2018 <zhoupans_mail@163.com>Date:   Mon Jul 20 21:38:12 2015 +0800    readme.txt first push
The preceding content shows the exact time of each submission that you have submitted three times. You will surely feel that you can see what the history of each submission is, and you cannot return it. However, this is true.
In git, HEAD represents the current version. The previous version is represented by HEAD ^. The previous version can be represented by HEAD ^. Of course, up to 100 characters can be written as 100 ^ characters, but I feel very troublesome. I believe you are the same, so there is another representation method, HEAD ~ 100. I learned how to express the historical version. The following shows how to roll back the historical version. We call it time-space shuttle.
$ Git reset -- hard HEAD ^ // return to the previous version
As for how to use the hard parameter, you will know later. Now, we only need to take it with reporters every time. If you submit a large number of times, you may be too troublesome to count each time, now there is a simple way to copy the version id to implement rollback. Version id is a string such as a character following the master in the content after each successful commit, hexadecimal. As follows:
[master 51f8f75] readme.txt second push1 file changed, 1 insertion(+)
The version id is 51f8f75.
$ Git reset 51f8f75 // returns the status of the second commit
If the terminal is closed, what should I do if I cannot find the submitted id? Don't worry, you can use:
$ git reflog readme.txt 
The following error occurs:
b480dd2 HEAD@{0}: commit: readme.txt third push51f8f75 HEAD@{1}: commit: readme.txt second pushac6574f HEAD@{2}: commit: readme.txt first push
It shows your historical submitted version id and so on. git's work zone and temporary storage zone have talked about so many hands-on practices. It is estimated that everyone is tired of hands. Let's talk about some theory here, just a moment.
The workspace, as its name implies, is the place where the job is located. It generally refers to the folder you initialize and contains a hidden folder. git. The temporary storage area is the place where the files are temporarily stored. However, the temporary storage area cannot be seen. After git add is used, the files are put into the temporary storage area from the work area and added multiple times, there will be multiple files in the temporary storage area. You can use git commit to submit all the files to the version library at a time. This is hard to understand. We strongly recommend that you press here:
http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/0013745374151782eb658c5a5ca454eaa451661275886c6000
7. Undo modification the previous version is returned. Here we will talk about undo modification. If you do not have add or commit
$ git checkout –readme.txt
The workspace modification will be discarded, but if you should add but not commit, you can use
$ git reset HEAD readme.txt 
Undo the modification of the temporary storage area, put it back into the workspace, and then use git checkout -readme.txt to discard the modification of the workspace.
 
If you have added & commit, consider rolling back to the previous version.
8. when you delete a file, you can directly delete the file in the graphic interface or use the rm command to delete it. However, in this case, the file in the workspace and version library is inconsistent in git, it will cause a lot of troubles. To avoid such incidents, we strongly recommend that you use:
$ git rm readme.txt
Delete the files in the workspace, and then
$ git commit -m “×××”
Submit the deletion changes.
 
Reference: http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000
 
 
 

Copyright Disclaimer: This article is an original article of the blogger. It can be reproduced without the permission of the blogger, but the source must be indicated. I will reserve the right to pursue accountability.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.