zoukankan      html  css  js  c++  java
  • 【工具】Git使用

    一:基本配置

    git init: 初始化仓库

    git clone: 从远程克隆仓库到本地

    git add <file>: 添加文件到暂存区

    git commit -m "xxx": 提交暂存区文件

    二:config命令

    配置文件:

        system: /etc/gitconfig

        global: #HOME/.gitconfig

    [user]
            name = xxxx
            email = xxxx@163.com

        local: $PROJECT/.git/config

    [core]
            repositoryformatversion = 0
            filemode = false
            bare = false
            logallrefupdates = true
            symlinks = false
            ignorecase = true
    [remote "origin"]
            url = git@github.com:skywind3000/awesome-cheatsheets.git
            fetch = +refs/heads/*:refs/remotes/origin/*
    [branch "master"]
            remote = origin
            merge = refs/heads/master

         workree: git 2.6引入的特性

    git config --list: 列出所有

    user.name=xxxx
    user.email=xxxxxx@163.com
    core.repositoryformatversion=0
    core.filemode=false
    core.bare=false
    core.logallrefupdates=true
    core.symlinks=false
    core.ignorecase=true
    remote.origin.url=git@github.com:skywind3000/awesome-cheatsheets.git
    remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
    branch.master.remote=origin
    branch.master.merge=refs/heads/master

    三:查看状态&对比文件

    git status: 查看状态

        git status -s: 查看状态

    git diff <file>: 对比文件(默认对比工作区和库上代码)

        git diff HEAD -- <file>: 对比HEAD指针和当前工作区文件的差异

        git diff --cached: 对比HEAD指针和暂存区

        git diff --staged: 对比?

        git diff --check <file>: 查看是否有空白错误?

        git diff --cached <file>: 查看已经ADD的内容?

    四:查看提交历史

    git log

        git log -n: 查看n条提交记录

        git log <branch> -n: 查看分支最近n条提交

        git log --stat: 历次commit的文件变化

        git log --shortstat: 只显示总文件和行数变化

        git log --name-status: 显示新增、修改、删除的文件清单

        git log commit..commit: 对比两次commit

        git log -p: 历次commit的内容增删

        git log -p -W: 历次commit的内容增删,同时显示上下文

    二:删除&撤销&回退

    git checkout -- <file>: 撤销工作区文件

    git restore <file>: 撤销工作区文件

    git reset HEAD <file>: 撤销git add

    git reset --hard HEAD^: 撤销git commit

    git rm/add <file>:

    git rm --cache <file>: 从暂存区删除文件

    五:关联远程仓库

    git remote add origin <remote_address>:

    git remote rm origin:

    git push -u origin master:

    git push origin master:

    六:分支管理

    git branch <branch>: 创建新分支

    git checkout <branch>: 切换到指定分支

    git switch <branch>: 切换到指定分支

    git checkout -b <branch>: 创建并切换到指定分支

    git switch -b <branch>: 创建并切换到指定分支

    git branch: 查看已有分支

    git merger: 合并分支

    git branch -d: 删除分支

    七:暂存文件

    git stash save: 暂存当前文件

    git stash list: 列出暂存文件

    git stash pop: 恢复现场

    git stash apply: 恢复指定现场

    git stash drop: 丢弃某个修改

    博客签名的内容
  • 相关阅读:
    Junit单元测试学习笔记(一)
    perl 函数参数传递与返回值(一)
    Oracle blob字段类型 文件读写实例
    测试沙龙的一些感悟
    常用排序算法选择排序
    perl 哈希(hash)学习笔记(一)
    perl 自定义包/模块的使用(正则表达式匹配email地址和ip)
    常用排序算法冒泡排序
    如何使用excel计算工龄
    畅想(3)打通编程的任督二脉 人工智能
  • 原文地址:https://www.cnblogs.com/happylich/p/12186785.html
Copyright © 2011-2022 走看看