Git learning Summary (1): git learning Summary
Preface:I had a chance to learn about a website that Mr. Liao learned about Git by accident. It was very detailed and easy to understand, after learning, I decided to summarize the essence of Miss Liao's post (equivalent to taking notes ~~), It is also convenient for future query and consolidation, and we hope you will share with us! View the original post of instructor Liao! |
1. Install Git
Here, I will only introduce how to install Git in Linux. If you need to know how to install Git in Unix, Mac, and Windows systems, You Can Baidu, or refer to the Git learning website provided at the beginning of this post for query.
(1) run the git command to check whether the system has installed Git. The following situations may occur:
$ gitThe program 'git' is currently not installed. You can install it by typing:sudo apt-get install git
(2) You can run a sudo apt-get install git command to install Git. If your Linux version is old, you can run the sudo apt-get install git-core Command to install Git.
2. Create a version library repository
~ /Workspaces $ mkdir MaxinGit // create a directory ~ /Workspaces $ cd MaxinGit // enter the directory ~ /Workspaces/MaxinGit $ pwd // display directory path/home/xin02.ma/workspaces/MaxinGit
~ /Workspaces/MaxinGit $ git init // use the git init command to program this directory to the Git-managed repository Initialized empty Git repository in/home/xin02.ma/workspaces/MaxinGit /. git // This directory is empty
~ /Workspaces/MaxinGit $ ls-ah... git // you can find an additional. git directory. Do not modify it manually!
3. Add files to the version Library
Compile a testdemo.txt file with the following content:
Git is a version control system.Git is free software.
Perform the following two steps:
(1) Add
~/workspaces/MaxinGit$ git add testDemo.txt
(2) Submit (add multiple times and commit together)
~ /Workspaces/MaxinGit $ git commit-m "wrote a testDemo file" // What is entered after-m is the description of this submission [master (root-commit) d1cee39] wrote a testDemo file1 file changed, 2 insertions (+) // a file is modified and two lines of create mode 100644 testDemo.txt are inserted.
Summary:
(1) initialize a Git repository and use the git init command.
(2) add a file to the Git repository in two steps: Step 1: Use the command git add <file> to add multiple files repeatedly;
Step 2: Run git commit.
4. modify files
Modify the testDemo file as follows:
Git is a distributed version control system.Git is free software.
Run the git status Command to view the result:
~ /Workspaces/MaxinGit $ git status // master the current status of the Repository
You can use the git diff command to view the modified content of the file:
~/workspaces/MaxinGit$ git diff testDemo.txt
Now, we can execute the git add command. Before executing the git commit command, run git status again to check the status of the version Library:
~/workspaces/MaxinGit$ git add testDemo.txt~/workspaces/MaxinGit$ git status
We can find that the changes to be submitted include the testDemo. text File. Now we can git commit:
~/workspaces/MaxinGit$ git commit -m "add distributed"
[master fe73dca] add distributed
1 file changed, 1 insertion(+), 1 deletion(-)
Now, check the status of git status:
~/workspaces/MaxinGit$ git status
Git tells us that there are no changes to be submitted, and the working directory is clean.
5. Version rollback
In Git, we can use the git log command to view the content of each modification:
~/workspaces/MaxinGit$ git log
If you are too confused about the output information, try to add--pretty=oneline
Parameters:
~/workspaces/MaxinGit$ git log --pretty=oneline
You can use the version rollback command git reset to roll back to the previous version:
~/workspaces/MaxinGit$ git reset --hard HEAD^
HEAD is now at d1cee39 wrote a testDemo file
We found that the previous version has been rolled back.
Now let's take a look at git log:
~/workspaces/MaxinGit$ git log
If, at this time, you want to roll back to the latest version, what version? We can use the following code:
~ /Workspaces/MaxinGit $ git reset -- hard fe73dca // fe73dca indicates the commit ID number of the latest version, and the version number does not need to be fully written.
HEAD is now at fe73dca add distributed
Git provides a git reflog command to record the log information and operation commands for each modification. The Code is as follows:
~/workspaces/MaxinGit$ git reflog
In this case, we can find the modified operation command and the corresponding commit id. In this way, we can quickly roll back to any version through git reset -- hard <id>.
6. Undo the modification.
(1)we continue to modify the testdemo.txt file and add a line of statement:
Git is a distributed version control system. Git is free software. I hate money. // Add a statement
At this point, you find that we all like money. What should we do? You can delete it manually, but here is another method. Let's take a look at git status and check the result:
~/workspaces/MaxinGit$ git status
We found a statement: (use "git checkout -- <file>... "to discard changes in working directory) can discard modifications to the workspace (the region where files are created and modified is the workspace:
~ /Workspaces/MaxinGit $ git checkout -- testDemo.txt // -- very important. If there is no --, direct git checkout is the command to switch the branch ~ /Workspaces/MaxinGit $ git status # On branch masternothing to commit (working directory clean)
At this point, we found that the modification was revoked!
Summary:Next, we will discuss how to undo the modification if you add it accidentally. The next post will soon be available to you! |