zoukankan      html  css  js  c++  java
  • 记一些常用的git命令

    1,初始化git仓库 

    git init

      在当前目录新建一个git 代码库

    git init [project-name] 
    新建一个目录,将其初始化为Git代码库

    2,克隆远程代码

    git clone ssh://git@git.xxxxxxxxxxx.com:2228/dj_fe/dj_res.git(项目地址)
    git clone https://git.xxxxxxxx.com/dj_fe/dj_res.git(项目地址)

    项目地址可分为https url和SSH url,

    常用的https url 操作比较简单,不需要提前配置,但是每次fetch和push代码都需要输入账号和密码,这也是https方式的麻烦之处

    使用SSH url 需要提前配置和添加好SSH key,因此你对这个项目需要有权限,

    关于具体如何查看和添加ssh key 

    https://blog.csdn.net/fastjack/article/details/79757520

    3,git 配置文件config用户名和邮箱的设置和查看

      3.1 设置用户名

    git config --global user.name "yourname"
    

      3.2 设置用户邮箱

    git config --global user.email myemail@qq.com 
    

      3.3 查看git设置列表信息

    git config --list
    

      3.4 查看用户名和邮箱

    git config user.name
    git config user.email

    4,一些查看命令

     4.1 查看项目的历史信息

    git log

     4.2 查看项目状态

    git status

    用于显示工作目录和暂存区的状态。使用此命令能看到那些修改被暂存到了, 哪些没有,

    git status不显示已经commit到项目历史中去的信息

     4.3 查看暂存区和工作区的差异

    git diff
    

     显示暂存区和上一个commit的差异

    git diff --cached[file]
    

     4.4 查看本地分支和远程分支的追踪关系

    git branch -vv
    

    5,拉取最新的代码

    git pull
    

    6,添加文件到暂存区

     6.1添加指定文件到暂存区

    git add [file1] [file2]...
    

     6.2添加当前目录的全部文件到暂存区

    git add .
    

      注意是个 " . "   注意是个 " . "  注意是个 " . "

    7, 代码提交

     7.1 提交暂存区到仓库区

    git commit -m"关于本次提交的信息,方便之后的查询"
    

     7.2 提交暂存区的指定文件到仓库区

    git commit [file1] [file2] ... -m"关于本次提交的信息"
    

     7.3 提交暂存区自上次 commit 的变化,直接到仓库区

    git commit -a
    

    8, 分支管理

     8.1 查看分支

    git branch         // 查看呢所有本地分支
    git branch -r     // 查看所有远程分支
    git branch -a      // 查看所有分支分支 ,本地分支在前,远程分支在后,颜色会有区别
    

    8.2 切换分支  并更新工作区

    git checkout [name]    // 切换分支  直接切换至远程分支的话,会在本地建立一个和远程分支具有追踪关系的本地分支,可以通过 git branch -vv 查看
    

      

    8.3 新建分支

    git branch [name]           //新建一个分支,不切换至该分支
    git checkout -b [name]    //新建一个分支,并切换至该分支 相当于git checkout 和git branch 的合并写法
    

     8.4 删除分支

    git branch -d [name]      //删除本地分支

    9,撤销操作

     9.1 恢复暂存区的指定文件到工作区

    git checkout [file]                //恢复暂存区的指定文件到工作区
    git checkout [commit] [file]       //恢复某个commit 的指定文件到暂存区和工作区
    git checkout .                     //恢复暂存区的所有文件到工作区

     9.2 重置暂存区

    git reset [file]                       //重置暂存区的指定文件,与上一次commit保持一致,但工作区不变
    
    git reset --hard                       //重置暂存区与工作区,与上一次commit 保持一致
    
    git reset [commit]                    //重置当前分支的指针为指定commit,同时重置暂存区,但工作区不变
    git reset --hard [commit]             //重置当前分支的指针为指定commit, 同时重置暂存区和工作区,与指定commit -致
    
    git reset --keep [commit]             //重置当前head为指定commit, 但保持暂存区和工作区不变
    

      

     

    10,推送分支

    git push  // 推送本地分支到远程分支,记得先git pull ,避免冲突

      

    git remote prune origin   // 同步 本地显示的远端分支命令
    

      

    史上最浅显易懂的Git教程!https://www.liaoxuefeng.com/wiki/896043488029600

    更多git参考http://www.ruanyifeng.com/blog/2015/12/git-cheat-sheet.html

     
  • 相关阅读:
    [Paper Review]Distilling the Knowledge in a Neural Network,2015
    Taylor Series and Gradient Descent
    Regularization from Large Wights Perspective
    Generative Model vs Discriminative Model
    State Function Approximation: Linear Function
    Temporal-Difference Control: SARSA and Q-Learning
    php扩展(centos+php7.2)---Composer: The requested PHP extension ext-intl * is missing from your system
    docker常用命令
    cURL error 60: SSL certificate problem: unable to get local issuer certificate
    【Magento 2学习】
  • 原文地址:https://www.cnblogs.com/jswzy/p/13305021.html
Copyright © 2011-2022 走看看