Simple git-related commands

Source: Internet
Author: User
Tags file copy

First-use advice see this ppt:http://www.bootcss.com/p/git-guide/

Cloning from an existing warehouse

This requires a git clone command. If you are familiar with other VCS such as Subversion, you may have noticed that the use is clone not checkout . This is a very important difference, and Git collects all the data from the project history (each version of each file), and there are local data clones on the server. In fact, even if the server's disk fails, any cloned client can rebuild the repository on the server and go back to the original state of the clone (although some server-side hook settings may be lost, all versions of the data still remain)

The command format for the Clone warehouse is git clone [url] . For example, to clone the Ruby language Git code repository Grit, you can use the following command:

$ git clone git://github.com/schacon/grit.git

This creates a directory in the current directory that grit contains a .git directory that holds all the downloaded version records and then extracts the latest version of the file copy. If you enter this new grit directory, you will see that all the files in the project are already inside, ready for future development and use. 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

The only difference is that the new catalog is now mygrit , and the rest is the same as the top.

Git supports many data transfer protocols. The previous example uses a git:// protocol, but you can also use http(s):// or [email protected]:/path.git represent the SSH Transfer protocol.

Track new files

Use the command to git add start tracking a new file. So, to trace the README file, run:

$ git add README

Run the command at this point and git status you will see that the README file has been tracked and is in a staged state:

$ git status    # On branch master    # Changes to be committed:    # (use "git reset HEAD <file>..." to unstage)    #    # new file: README    #

As long as the "changes to be committed" line below, it means that the state is staged. If committed at this time, then the version of the file will be retained in the history at this moment.

git addyou can indicate the path to the file or directory you want to trace later. If it is a directory, it means to recursively track all files in that directory. In fact, git add the subtext is to put the target file snapshot into the staging area, that is, the add file into staged areas, while the files that have not been tracked are marked for tracking. This is a good way to understand the actual meaning of the subsequent add operation. )

git add .

Commit all files in this directory to the buffer

Submit Updates

Now the staging area is ready to be submitted. Before you do, make sure that there are any modified or newly created files that have not yet git add been submitted, otherwise they will not be recorded at the time of the changes that have not yet been staged. So, each time you prepare to commit, first use to git status see, is not all staged, and then run the commit command git commit :

$ git commit

This way, a text editor is launched to enter the instructions for this submission. (The software specified by the shell's environment variables is enabled by default $EDITOR , typically vim or emacs.) Of course, you can use the git config --global core.editor command to set your favorite editing software in the same way as described in Chapter I. )

The editor displays text messages similar to the following (shown in this example using Vim's onscreen display):

# Please enter the commit message for your changes. Lines starting    # with ‘#‘ will be ignored, and an empty message aborts the commit.    # On branch master    # Changes to be committed:    # (use "git reset HEAD <file>..." to unstage)    #    # new file: README    # modified: benchmarks.rb    ~    ~    ~    ".git/COMMIT_EDITMSG" 10L, 283C

As you can see, the default commit message contains the last run git status output, placed in the comment line, and at the beginning there is a blank line for you to enter the submission instructions. You can completely get rid of these comment lines, but it's okay to keep them, and how much can help you remember what this update is about. (If this is not enough, you can use the -v option to include each line of the modified difference in the comment.) When you exit the editor, Git discards the comment lines and submits the description and the update to the warehouse.

Alternatively, you can submit the update in one line of commands with the-m parameter followed by the commit description:

$ git commit -m "Story 182: Fix benchmarks for speed"    [master]: created 463dc4f: "Fix benchmarks for speed"    2 files changed, 3 insertions(+), 0 deletions(-)    create mode 100644 README

Push data to a remote repository

Project to a stage, to share with others the current results, you can push data from the local warehouse to the remote repository. The command to implement this task is simple: git push [remote-name] [branch-name] . If you want to push the local master branch to the origin server (again, the clone operation will automatically use the default Master and Origin names), you can run the following command:

$ git push origin master

This command completes the task as expected only if there are write permissions on the cloned server, or if no one else is pushing the data at the same time. If someone else has pushed a few updates before you push the data, your push will be dismissed. You have to crawl their updates locally and merge them into your own project before you can push them again.

Resources:

Pro Git (Chinese version)
http://git.oschina.net/progit/2-git-%e5%9f%ba%e7%a1%80.html#2.1-%e5%8f%96%e5%be%97%e9%a1%b9%e7%9b%ae%e7%9a%84- git-%e4%bb%93%e5%ba%93

Simple git-related commands

Related Article

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.