zoukankan      html  css  js  c++  java
  • git

    参考:阮一峰  GitHub指令  详解  交互式学习
    个人总结连接git:
    下载git,git.exe添加到环境变量
    创建一个目录进入cmd,git clone +地址(应该要在github上加入ssh)
    后面要同步代码,进入该目录(项目目录,有.git),git pull
    git 命令大全:戳  this  here

    相关命令:

     1 配置信息
     2 git config --list # 查看配置
     3 
     4 git config --local # 当前仓库
     5 git config --global当前用户所有仓库
     6 git config --system # 当前系统
     7 
     8 git config --global user.name 'Gruel'
     9 git config --global user.email 'clayzwq@gmail.com'
    10 
    11 # 关联github远程仓库
    12 echo "# GolangNote" >> README.md
    13 git init
    14 git add README.md
    15 git commit -m "first commit"
    16 git remote add origin git@github.com:OvernightGruel/GolangNote.git
    17 git push -u origin master
    18 
    19 git init [project_name]  # 新建本地仓库
    20 git mv old_name new_name # 重命名文件
    21 git rm file_name         # 删除文件
    22 
    23 git add -A                     # 将文件的修改,文件的删除,文件的新建,添加到暂存区
    24 git add -u                     # 将文件的修改、文件的删除,添加到暂存区
    25 git add .                      # 将文件的修改,文件的新建,添加到暂存区
    26 git commit -am 'content'       # git add + git commit
    27 git commit --amend             # 修改最近一次commit信息
    28 git rebase -i commit^  
    29                        reword  # 修改任意commit信息
    30                        squash  # 合并commit
    31 
    32 git checkout --file file_name       # 工作区文件回退
    33 
    34 git reset HEAD                      # 清空暂存区,回到指定版本
    35 git reset HEAD -- file_name         # 暂存区文件回退到工作区
    36 git reset —hard [HEAD]              # 清空工作区和暂存区,回到指定版本
    37 
    38 git diff [file_name]                                            # 查看工作区和暂存区区别
    39 git diff --cached [file_name]                                   # 查看暂存区与原版本区别
    40 git diff branch/HEAD/commit branch/HEAD/commit [-- file_name]   # 查看版本间区别
    41 
    42 HEAD                                   # 本版本
    43 HEAD^  HEAD~1                          # 上版本
    44 HEAD^^..  HEAD~n                       #上n个版本
    45 
    46 git log             # 查看当前分支日志
    47          -n         # 限定日志数量
    48          --online   # 只显示提交信息
    49          --all      # 所有分支日志
    50          --graph    # 图形显示
    51 
    52 git branch                           # 查看当前分支
    53            -v                        # verbose详细信息
    54            -a                        # 所有分支
    55            -d/-D name                # 删除指定分支
    56            -m old_name new_name      # 修改分支名
    57 git push origin --delete branch_name # 删除远程分支
    58 
    59 git checkout -b branch_name [branch/commit] # 创建并切换分支
    60 
    61 git clone --bare git_address name # 克隆库到本地
    62 git remote add name git_address   # 关联远程库
    63 
    64 git merge        # 分支合并
    65          --abort # 中止合并            
    66 
    67 git push         # 本地推到远程
    68 git fetch        # 远程拉到本地
    69 git pull         # git fetch + git merge
    70 
    71 git stash         # 储藏当前工作
    72 git stash list    # 查看储藏栈
    73 git stash apply   # 提取最新工作
    74 git stash pop     # 提取最新工作并从栈删除
    75 
    76 git symbolic-ref --short HEAD  # 获取当前分支名
    77 
    78 git submodule add 仓库地址 路径                # 添加git子模块 
    79 git rm –cached                                 # 删除子模块(先删除.gitmodules)
    80 git submodule update --init --recursive        # 更新子模块
    View Code

    workspace: 本地的工作目录。(记作A)
    index/stage:暂存区域,临时保存本地改动。 (记作B)
    local repository: 本地仓库,只想最后一次提交HEAD。(记作C)
    remote repository:远程仓库。(记作D)

    初始化:

    1 git init //创建
    2 git clone /path/to/repository //检出
    3 git config --global user.email "you@example.com" //配置email
    4 git config --global user.name "Name" //配置用户名
    View Code

    操作:

     1 git add <file> // 文件添加,A → B
     2 git add . // 所有文件添加,A → B
     3 git commit -m "代码提交信息" //文件提交,B → C
     4 git commit --amend //与上次commit合并, *B → C
     5 git push origin master //推送至master分支, C → D
     6 git pull //更新本地仓库至最新改动, D → A
     7 git fetch //抓取远程仓库更新, D → C
     8 git log //查看提交记录
     9 git status //查看修改状态
    10 git diff//查看详细修改内容
    11 git show//显示某次提交的内容
    View Code

    撤销操作:

    1 git reset <file>//某个文件索引会回滚到最后一次提交, C → B
    2 git reset//索引会回滚到最后一次提交, C → B
    3 git reset --hard // 索引会回滚到最后一次提交, C → B → A
    4 git checkout // 从index复制到workspace, B → A
    5 git checkout -- files // 文件从index复制到workspace, B → A
    6 git checkout HEAD -- files // 文件从local repository复制到workspace, C → A
    View Code

    分支相关:

    1 git checkout -b branch_name //创建名叫“branch_name”的分支,并切换过去
    2 git checkout master //切换回主分支
    3 git branch -d branch_name // 删除名叫“branch_name”的分支
    4 git push origin branch_name //推送分支到远端仓库
    5 git merge branch_name // 合并分支branch_name到当前分支(如master)
    6 git rebase //衍合,线性化的自动, D → A
    View Code

    冲突处理:

    1 git diff //对比workspace与index
    2 git diff HEAD //对于workspace与最后一次commit
    3 git diff <source_branch> <target_branch> //对比差异
    4 git add <filename> //修改完冲突,需要add以标记合并成功
    View Code

    git连接github

     1 1.注册github账号
     2 2.下载安装git 客户端 (安装后 包含git gui,git bash,git cmd)
     3 3.打开git bash (bash是cmd的升级版,建议使用bash)
     4 输入如下命令,并按回车
     5 git config --global user.name "github用户名"
     6 git config --global user.email "github邮箱"
     7 ssh-keygen -t rsa -C "github邮箱" //生成ssh key
     8 4.ssh key 在C:Userslwx655516.ssh的 id_rsa.pub
     9 复制粘贴至github settings / ssh and GPG keys 粘贴至ssh key
    10 5.测试连接
    11 ssh -T git@github.com
    View Code
  • 相关阅读:
    项目总结-驱虫市场电商数据挖掘
    电商数据处理项目
    Hive sql常用函数公式整理
    拉勾网‘数据分析师’职位招聘信息数据爬取
    鸢尾花数据(PCA主成分分析)
    项目总结-信用评分卡
    某保险公司参保客户分析
    Excel自定义格式参数
    VS2013创建ADO实体模型报:Microsoft.SqlServer.Management.Sdk.Sfc, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91
    AngularJS-学习
  • 原文地址:https://www.cnblogs.com/luoyangyang/p/10255276.html
Copyright © 2011-2022 走看看