美文网首页iOS开发者日记
Mac 下 Git 的基础命令行操作

Mac 下 Git 的基础命令行操作

作者: DeadRabbit | 来源:发表于2016-10-18 16:46 被阅读258次

    因为Mac下已经自带了git,所以我们跳过此步骤,如果你是Linux的其他系统,可以使用一下代码进行安装:

    sudo apt-get install git-core //安装Git

    用户配置

    git config --global user.name "Your Name" //配置用户名称
    git config --global user.email "Your Email" //配置用户邮箱
    git config --list //查看配置信息

    第一次初始化git版本库
    开始一个新的项目,初始化新的代码仓库,要对现有的某个项目开始用 Git 管理,只需到此项目所在的目录,执行:

    git init

    会在当前目录下生成一个.git目录,包含了所有git需要的数据和资源
    进行git添加,提交,推送操作

    touch README //创建README
    git add . //添加左右新增或者改动过的文件
    git commit -a -m "添加README" //提交变更到本地版本库
    git push origin <branch name> //推送本地版本库到远程仓库

    git克隆远程仓库

    //Git本身的源代码你既可以用 git:// 协议来访问:
    git clone git@git.jianshu.net:******/****.git
    //也可以通过http 协议来访问:
    git clone https://git.jianshu.net/******/****.git
    //自定义目录名称,如果不自定义,默认为远程仓库的项目目录名称
    git clone https://git.jianshu.net/******/****.git mygrit

    Git分支操作

    查看分支 git branch
    创建分支 git branch <branch name>
    切换分支 git checkout branch
    合并分支 git merge <branch name> //合并某分支到当前分支
    删除分支git branch -d <branch name>

    mac git --help
    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

    相关文章

      网友评论

        本文标题:Mac 下 Git 的基础命令行操作

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