zoukankan      html  css  js  c++  java
  • git命令

    cd 进入 cd e:
    ls 查看目录
    mkdir 创建文件夹
    git config --global user.name "songzhikui"
    git config --global user.email "songzhikui@live.com"
    git config --list
    git status 查看工作状态
    git clone https://github.com/songzhikui/songzk.git
    https://github.com/songzhikui/SongZhiKui.git
    git add index.html 工作区添加文件到暂存区
    git add . 工作区添加所有文件到暂存区
    git commit -m "注释" 从暂存区上传到版本库
    git commit -a -m "注释" 工作区直接上传到版本库
    git log 查看提交历史
    git diff 工作区与暂存区的对比
    git diff --cached(--staged) 暂存区与版本库的对比
    git diff master 工作区与版本库之间的对比
    git reset HEAD index.html 从暂存区撤销到工作区
    git checkout -- index.html 从工作区撤销到暂存区或版本区的状态
    git commit -m "注释" -- amend 撤销提交到版本库的文件、
    q退出log

    Git命令
    删除
    git rm index.html 删除暂存区的文件
    git rm -f index.html 删除工作区和暂存区的文件 一起删除
    git rm --cached index.html 删除暂存区的文件 工作区会保留文件
    恢复
    git checkout commit_id index.html 恢复已删除的文件 查看历史log 复制最近删除的id号
    git reset --hard commit_id 恢复版本(回到过去)
    HEAD^
    HEAD~<num>
    git reflog 恢复版本(回到现在)

    git remote 查看远程名称
    git remote add 改远程的名字
    git remote -v 查看远程地址
    git push origin master 上传到github网站 master分支

    多人协作解决冲突
    1:
    git fetch 从github 从网站上拉取数据 【手动方式进行合并(最好用这种)】
    git diff master origin/master 本地对比github网站(红色代表本地,绿色代表远端)
    git merge origin/master 手动合并
    2:
    git pull 从github网站上拉取数据 自动方式进行合并(把远端的替换合并本地的)

    分支:
    1.
    git branch 查看分支
    * master
    git branch new1 创建分支:new1
    * master
    new1
    git checkout new1 切换到new1分支
    2.快速方法:
    git checkout -b new1 创建(分支)并且切换到分支

    git branch --merged 查看合并的分支
    git branch --no-merged 查看未合并的分支
    git branch -d new1 删除new1分支(合并过的分支)
    git branch -D new1 删除new1分支(未合并过的分支)

    git merge new1 合并分支


    标签
    git tag v1.0


    --------------------------------------------------------------------
    $cd ~/hello-world //到hello-world目录

    $git init //初始化

    $git add . //把所有文件加入到索引(不想把所有文件加入,可以用gitignore或add 具体文件)

    $git commit //提交到本地仓库,然后会填写更新日志( -m “更新日志”也可)

    $git remote add origin git@github.com:WadeLeng/hello-world.git //增加到remote

    $git push origin master //push到github上

    2.更新项目(新加了文件):

    $cd ~/hello-world

    $git add . //这样可以自动判断新加了哪些文件,或者手动加入文件名字

    $git commit //提交到本地仓库

    $git push origin master //不是新创建的,不用再add 到remote上了

    3.更新项目(没新加文件,只有删除或者修改文件):

    $cd ~/hello-world

    $git commit -a //记录删除或修改了哪些文件

    $git push origin master //提交到github

    4.忽略一些文件,比如*.o等:

    $cd ~/hello-world

    $vim .gitignore //把文件类型加入到.gitignore中,保存

    然后就可以git add . 能自动过滤这种文件

    5.clone代码到本地:

    $git clone git@github.com:WadeLeng/hello-world.git

    假如本地已经存在了代码,而仓库里有更新,把更改的合并到本地的项目:

    $git fetch origin //获取远程更新

    $git merge origin/master //把更新的内容合并到本地分支

    6.撤销

    $git reset

    7.删除

    $git rm * // 不是用rm

    //——————————常见错误———————————–

    1.$ git remote add origin git@github.com:WadeLeng/hello-world.git

    错误提示:fatal: remote origin already exists.

    解决办法:$ git remote rm origin

    然后在执行:$ git remote add origin git@github.com:WadeLeng/hello-world.git 就不会报错误了

    2. $ git push origin master

    错误提示:error:failed to push som refs to

    解决办法:$ git pull origin master //先把远程服务器github上面的文件拉先来,再push 上去。

  • 相关阅读:
    Orcale三层嵌套实现分页功能
    在VM虚拟机上安装Microsoft Dynamics CRM 2016 步骤图解及安装注意事项
    CSS 选择器 关系
    C#获取当前程序运行路径的方法集合//获取当前进程的完整路径
    连接QuickBooks Online实现于IOS App数据同步功能的个人记录
    Posix定义的进程线程同步系统调用
    SQL SERVER 数据库事物日志 备份 收缩 腾出空间
    JAVABEAN递归转MAP实现
    第一次迭代——视频点播系统
    cstddef定义了NULL
  • 原文地址:https://www.cnblogs.com/sunnychen/p/6141857.html
Copyright © 2011-2022 走看看