Hub命令的基本应用

2017-11-28  本文已影响0人  Michaelhbjian

在使用GitHub的过程中,会不避免地频繁接触到git命令。而在这里介绍的hub命令则是一个封装了git命令的命令行工具,能够辅助用户使用GitHub。这是个很方便的工具,经常使用Github的用户可以尝试一下。

1.概要

hub命令将通常的git命令进行封装并增加几项功能,就可以调用GitHub的API发送命令。这个是官方介绍:

git + hub = github

hub is a command line tool that wraps git in order to extend it with extra features and commands that make working with GitHub easier.

$ hub clone rtomayko/tilt

expands to:

$ git clone git://github.com/rtomayko/tilt.git

hub is best aliased as git, so you can type $ git <command> in the shell and get all the usual hub features. See "Aliasing" below.

2.安装(Standalone模式)

以下是Windows版的安装方法(Linux版安装方法一样)
第一步:下载hub源码

image.png
第二步:先进入hub目录,然后添加环境变量参数,最后设置别名
image.png
第三步:输入git version后出现以下信息就是安装成功了
image.png
第四步:hub命令在首次访问GitHub的API时会询问用户名和密码(就是注册GitHub的账号和密码),输入完成之后就可以通过API操作GitHub了
image.png

3.常用命令

下面介绍下常用hub命令:

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)
   #使用hub clone命令,可以省去指定GitHub端仓库的部分
   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
  #hub push命令支持通知向多个远程仓库进行push操作
   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.

These GitHub commands are provided by hub:

   browse         Open a GitHub page in the default browser
   ci-status      Show the CI status of a commit
   compare        Open a compare page on GitHub
  #hub create命令适用于本地已经创建仓库,但GitHub端没有创建仓库的情况
   create         Create this repository on GitHub and add GitHub as origin
  #hub fork命令的功能与GitHub页面的Fork按钮相同。比如我们clone了其他用户的仓库,现在想Fork成自己的仓库,只需要执行hub fork
   fork           Make a fork of a remote repository on GitHub and add as remote
   issue          List or create issues
   pr             Work with pull requests
  #hub  pull-request命令为我们提供了创建Pull Request的功能,利用这个命令创建Pull Request可以不必访问GitHub页面
   pull-request   Open a pull request on GitHub
   release        List or create releases

学会了hub命令,可以减少git命令的输入,高效的操作了GitHub。

4.参考资料

hub命令帮助文档
hub源码与安装手册

上一篇下一篇

猜你喜欢

热点阅读