Git version control Management Learning Note 2--start

Source: Internet
Author: User

First make sure that Git is already installed in the system, and the Linux system used here.

First, the command line preliminary use: 1, git command:

Lists its options and the most commonly used subcommands. In the standard command format, the command represents the subcommands listed below.

[[email protected] ~]# git
2. Display version number:
[[email protected] ~]# git--1.7. 1
3, bare double Dash-the role of:

It is used to separate a series of parameters. For example, the following:

diff -w Master Origin--Tools/makerfile

The description of the command line here is just a simple description of the git command format.

Second, Git uses a quick start:

This will create a new repository, add some content, and then manage a series of revisions.

1. Create the initial repository:

Create a personal site project in the ~/public_html directory and put it in the Git repository.

mkdir~]# cd public_html/echo'My website is alive! ' > index.html

Execute git init and convert ~/public_html to git repository:

 in/root/public_html/.git/

The GIT init command creates a hidden directory: What is meant by the data inside the folder, followed by a description.

[[Email protected] public_html]# CD. Git[[email protected]. git]#pwd/root/public_html/. Git[[email protected]. git]# lltotal +drwxr-xr-x2Root root4096Nov in  -: -Branches-rw-r--r--1Root root theNov in  -: -Config-rw-r--r--1Root root theNov in  -: -Description-rw-r--r--1Root root atNov in  -: -HEADDRWXR-xr-x2Root root4096Nov in  -: -HOOKSDRWXR-xr-x2Root root4096Nov in  -: - Infodrwxr-xr-x4Root root4096Nov in  -: -OBJECTSDRWXR-xr-x4Root root4096Nov in  -: -Refs

In addition to a new. Git hidden folder in the ~/public_html directory, the entire directory structure does not change. Repositories that are hidden within. Git will be maintained by Git.

2. Add files to the repository:

Initially, each git repository is empty. In order to manage the content, you must explicitly add the file to the repository.

Here, all the files under the ~/public_html folder are added to the repository:

pwd/root/public_html[[email protected] public_html]# git Add.

Of course, you can also add a single file to the repository, such as only one index.html file here, we add it to the repository: (in fact, the above operation has already added index.html to the repository)

[[email protected] public_html]# git add index.html

After using the git add command, git knows that index.html is going to stay in the repository, but now it's just staging (staged) the file, which is the intermediate step before committing. Git intentionally separates the add and commit commands to avoid frequent changes.

Run the git status command to display the index.html in the middle state:

This command shows that the new file index.html will be added to the repository at the time of the next commit (commit).

Since Git records metadata at each commit (commit), including the log message and the author who made the change, a complete commit command is as follows:

" Initial contents of public_html " --author="nextflower <[email protected]>"[Master (Root-   110 deletions (-100644 index.html

You can import the following environment variables if you want to enter log messages through the editor at commit time and use Vim to edit them:

[Email protected] public_html]# export Git_editor=vim

Now look at git status:

This means that the working directory does not contain any unknown or changed files that are different from the repository.

3. Configuration Submission

Although you can use the-author parameter every time you commit to let git identify you, it's hard to get into trouble every time you enter it.

You can modify the author's information by using the following command:

" Nextflower "  "[email protected]"

You can also use environment variables git_authot_name and git_author_email to tell Git.

4. Re-submit:

Modify the index.html file here and resubmit it.

[Email protected] public_html]# CD ~/public_html/catMy web Site is alive!</body>151 deletions (-)

This may be confusing because the add command was not used before commit , so why?

Since this file has been added to the repository, there is no need to tell the file to the index.

In fact, when we modify the index.html file, if we use the git status command we will find that Git has automatically captured the file changes.

5. View Submissions:

The git log command results in a series of separate commits in the repository.

You can use git show + commit code to view the details of a specific submission: ( If you do not add a commit code, only the details of the most recent commit will be displayed )

You can also use Show-branch to provide a concise, single-line summary of the current development branch:

[email protected] public_html]# git show-branch-more =ten[master] firsr change[master^] Initial contents of public_html
6. View Submission Differences:

Use the full ID name of two commits and run Git diff:

7. Deletion and renaming of files in the repository:

Git version control Management Learning Note 2--start

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.