zoukankan      html  css  js  c++  java
  • git基础

    • 工作区:当前编辑的区域 红色

    • 缓存区:add 之后的区域 绿色

    • 本地仓库:commit之后的区域

    • 远程仓库:远程的区域

    一.简单的命令行入门

    1.git全局设置

    git config --global user.email 'adf@qq.com'  # 设置用户的邮箱
    git config --global user.name "xxx"  # 设置用户的用户名
    
    git config --global --unset user.email  # 删除用户的邮箱
    git config --global --unset user.name  # 删除用户的用户名
    

    2.创建git仓库

    mkdir '文件夹名字'
    cd '文件夹名'
    git init  # 初始化
    touch README.md
    git add README.md
    
    git commit -m 'first commit'  # 将缓存区的内容提交到本地仓库
    git remote add origin https://  # 设置远程仓库地址
    git push -u origin master  # 推送到远程仓库
    

    已有仓库?

    cd existing_git_repo
    git remote add origin https://
    git push -u origin master
    

    二.基本命令

    查看与添加到缓冲区

    git status  # 查看git的状态
    git add  # 将文件放到缓存区
    

    回退版本

    git log  # 查看当前版本之前提交记录
    git reset --hard hash值  # 回退到之前某次提交的地方 慎用
    git reflog  # 查看所有的提交记录
    git checkout filename  # 将指定文件回退到最近一次commit的地方,只对工作区做修改,缓存区不变 慎用
    
    git reset HEAD filename  # 将指定文件从缓存去拉取到工作区,不会覆盖原来的文件
    git diff  # 对比缓存区和工作区的区别
    git diff --cached  # 对比缓存区和本地仓库的区别
    

    添加别名

    git remote add origin https://github.com/417685417/cw.git
    

    克隆

    git clone [https://url.git](https://url.git/)
    

    拉取

    git push origin master 将本地的文件上传到远程仓库
    git pull origin master 将远程仓库的文件拉取到本地
    

    三 .stash快照

    创建一个快照

    git stash 
    

    取出快照并删除快照记录

    git stash pop 
    

    查看快照记录

    git stash list 
    

    删除快照

    git stash drop name 
    

    取出快照

    git stash apply name 
    

    异常解决

    • 因为线上版本跟本地版本库不一致,本地版本比线上新
    ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'https://github.com/417685417/cw.git' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Integrate the remote changes (e.g.                                          hint: 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
    
    • 冲突:同时修改了同一个文件的同一个位置,冲突自己解决
    Auto-merging templates/index.html CONFLICT (content): Merge conflict in templates/index.html Automatic merge failed; fix conflicts and then commit the result.
    
    • 因为没有权限
    Logon failed, use ctrl+c to cancel basic credential prompt. remote: Permission to 417685417/cw.git denied to WuPeiqi. fatal: unable to access 'https://github.com/417685417/cw.git/': The requested URL returned error: 403
    
  • 相关阅读:
    金山词霸注册表怎么删
    新手学习jquery
    《企业应用架构模式》(POEAA)读书笔记
    Silverlight 4 tools
    asp.net非常基础的面试题
    VS 2010 中文版正式版无法安装Silverlight4 Tools的解决办法
    OnPreRender(EventArgs e) 事件常用的方法
    各大搜索引擎网站登录入口
    向用户控件传递参数的问题
    URLRewriter
  • 原文地址:https://www.cnblogs.com/robertx/p/10933065.html
Copyright © 2011-2022 走看看