美文网首页
初识 Git

初识 Git

作者: iMark | 来源:发表于2016-06-14 12:45 被阅读43次

    [TOC]

    了解 Git


    Git is a fast, scalable, distributed revision control system with an unusually rich command set that provides both high-level operations and full access to internals.

    那为什么要使用Git呢?

    因为他们都在用Git...

    其实使用 Git 已经快俩月了,不过用的不多,而且基本上是基于 GitHub 的 windows 客户端操作的。想要真正理解 Git ,其实还是需要从命令行开始。

    工欲善其事必先利其器:
    git

    一个非常有用的 命令: git help everyday

    everyday Git with 20 commands or so

    其实使用命令行的都知道:
    git help

    git help
    DELL@DELL-PC MINGW64 ~/Desktop
    $ git help
    usage: git [--version] [--help] [-C <path>] [-c name=value]
               [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
               [-p | --paginate | --no-pager] [--no-replace-objects] [--bare]
               [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
               <command> [<args>]
    
    These are common Git commands used in various situations:
    
    start a working area (see also: git help tutorial)
       clone      Clone a repository into a new directory
       init       Create an empty Git repository or reinitialize an existing one
    
    work on the current change (see also: git help everyday)
       add        Add file contents to the index
       mv         Move or rename a file, a directory, or a symlink
       reset      Reset current HEAD to the specified state
       rm         Remove files from the working tree and from the index
    
    examine the history and state (see also: git help revisions)
       bisect     Use binary search to find the commit that introduced a bug
       grep       Print lines matching a pattern
       log        Show commit logs
       show       Show various types of objects
       status     Show the working tree status
    
    grow, mark and tweak your common history
       branch     List, create, or delete branches
       checkout   Switch branches or restore working tree files
       commit     Record changes to the repository
       diff       Show changes between commits, commit and working tree, etc
       merge      Join two or more development histories together
       rebase     Reapply commits on top of another base tip
       tag        Create, list, delete or verify a tag object signed with GPG
    
    collaborate (see also: git help workflows)
       fetch      Download objects and refs from another repository
       pull       Fetch from and integrate with another repository or a local branch
       push       Update remote refs along with associated objects
    
    'git help -a' and 'git help -g' list available subcommands and some
    concept guides. See 'git help <command>' or 'git help <concept>'
    to read about a specific subcommand or concept.
    

    如果在后面带上一个参数 -g 的话。。。


    git help -g
    DELL@DELL-PC MINGW64 ~/Desktop
    $ git help -g
    The common Git guides are:
    
       attributes   Defining attributes per path
       everyday     Everyday Git With 20 Commands Or So
       glossary     A Git glossary
       ignore       Specifies intentionally untracked files to ignore
       modules      Defining submodule properties
       revisions    Specifying revisions and ranges for Git
       tutorial     A tutorial introduction to Git (for version 1.5.1 or newer)
       workflows    An overview of recommended workflows with Git
    
    'git help -a' and 'git help -g' list available subcommands and some
    concept guides. See 'git help <command>' or 'git help <concept>'
    to read about a specific subcommand or concept.
    

    先看看这些基本的命令吧,真正的使用 Git 的时候还需要有远程仓库 repository,否则就是“无米炊”

    使用 Git 来工作


    接下来看看如何使用最基本的 Git 命令来完成工作。

    因为需要远程仓库的支持,所以我们应该先选择一个代码托管平台,比如说 码云,比如说 GitHub。我们的代码将托管在这些平台上,并使用 Git 工具来进行代码的更新(版本管理)

    在码云上创建与删除远程仓库

    OMG,我把密码忘了。。。。。。


    Git 全局设置(初次使用时设置):

    git config --global user.name "Mark_Han"
    git config --global user.email "hanshikaiapple@gmail.com"
    

    创建 git 仓库:

    mkdir DEMO
    cd DEMO
    git init
    touch README.md
    git add README.md
    git commit -m "first commit"
    git remote add origin https://git.oschina.net/markhan/DEMO.git
    git push -u origin master
    

    已有项目?

    cd existing_git_repo
    git remote add origin https://git.oschina.net/markhan/DEMO.git
    git push -u origin master
    

    Here is a cheat sheet for git
    https://services.github.com/kit/downloads/github-git-cheat-sheet.pdf

    相关文章

      网友评论

          本文标题:初识 Git

          本文链接:https://www.haomeiwen.com/subject/dakudttx.html