[Git Learning: Pro git (2)] Git basics

Source: Internet
Author: User
Tags file copy glob

Getting a Git Repository (get the project git repository)

One initializes the new warehouse in the working directory:

Git init

After initialization, a directory named. Git appears in the current directory, and all of the data and resources that git needs are stored in this directory. but for now, all the files and directories are initialized in accordance with the existing framework, but we haven't started tracking any of the files in the managed project.

$git Add *.c #git Add start trace file, begin to tracking a new file$git add Readme$git commit-m ' initial project version '
Two clones from an existing warehouse

Git Clone collects all the data from the project history (each version of each file), and there are local data clones on the server. Command format for cloned warehouses: git clone [url]

$git Clone Git://github.com/schacon/grit.git
under current directory, create a name ofThe directory for Grit, which contains a. git directory,used to save all downloaded version records, then remove the latest version of the file copy from

if you want to define a new project directory name when you are cloning, you can specify a new name at the end of the command above:

$ git clone git://github.com/schacon/grit.git Mygrit
Git supports many data transfer protocols. The previous example uses thegit://agreement, but you can also useHTTP (s)://orUser @server:/path.gitrepresents the SSH transport protocol.

Recording changes to the Repository (record every update to warehouse)

Check the current file status (Checking the status of Your files)

$git Statuson Branch masternothing to commit,working directory Clean#master branch All files not changed since last commit
Keep track of new files (Tracking)
$ vim readme$ git Statuson branch masteruntracked files:  (use "git add <file> ..." to include in what would be COM mitted)        Readmenothing added to commit but untracked files present (use "Git add" to track) $git add README  #开始跟踪文件 $ $ git Statuson Branch masterchanges to being committed:  (use "git reset HEAD <file> ..." to Unstage)        new file:
   readme  #README已暂存, if submitted, will be recorded in the version history
Staging modified Files

Modify the previously tracked file benchmarks.rb, and then run the status again

$ git Statuson Branch masterchanges to being committed:  (use "git reset HEAD <file> ..." to Unstage)        new file:
   readmechanges not staged for commit:  (use "git add <file> ..." To update what would be committed) (use  "G It checkout-<file>, .... To discard changes in working directory)        modified:   benchmarks.rb
$ git add benchmarks.rb #git add to put the tracked files into staging area $ git Statuson branch masterchanges to being committed:  (use "Git reset HEAD <file>, .... to unstage)        new file:   README        modified:   benchmarks.rb
git add can also be used to mark conflicting files as resolved when merging。

Some files are ignored (ignoring files)

Some files do not need to be included in Git management, and they do not always appear in the list of files that are not tracked. Typically, some auto-generated files, such as log files or temporary files created during compilation. We can create a file named. Gitignorede, which lists the file patterns to ignore, and the file format specification is as follows:

All empty lines or lines that start with the comment symbol # are ignored by Git. You can use the standard glob pattern matching. The match pattern is followed by a backslash (/) to indicate that the directory is to be ignored. to ignore files or directories other than the specified pattern, you can precede the pattern with an exclamation point (!). The so-called glob pattern refers to the simplified regular expression used by the shell. The asterisk (*) matches 0 or more arbitrary characters, and [ABC] matches any character in square brackets (this example either matches a, matches a B, or matches a C); The question mark (?) matches only one arbitrary character; If you use a dash to separate two characters in square brackets, Indicates that all of the two character ranges can be matched (for example [0-9] to match all numbers from 0 to 9).
View the new (viewing your staged and unstaged changes) that have been staged and not staged

To see which parts of a file that have not yet been staged have been updated, enter Git diff without adding parameters, which is the difference between the current file in the working directory and the snapshot of the staging area, which is what has not been staged since the modification.

$ git diffdiff--git a/benchmarks.rb b/benchmarks.rbindex 3cb747f. da65585 100644---a/benchmarks.rb+++ b/benchmarks.rb@@ -36,6 +36,10 @@ def main           @commit. parents[0].parents[0]. Parents[0]         end+        run_code (x, ' commits 1 ') do+          git.commits.size+        end+         run_code (x, ' commits 2 ') do           log = git.commits (' master ', log.size)           



[Git Learning: Pro git (2)] Git basics

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.