git初步使用笔记

Git安装使用

1、初始配置

  • 自报家门
$ git config --global user.name #你是谁
  • 联系方式
$ git config --global user.email #你的邮箱

2、代码管理(本地)

  1. 创建版本库

    $ cd E:/
    $ mkdir test
    $ git init
  2. 添加文件

    • 提交流程
    • 工作区开发——》(add)暂存区——》(commit)版本库
    $ git status #查看仓库状态
    $ git add .  #提交(所有)到暂存区
    $ git commit -m "init" #提交,-m是注释
  3. 删除文件

    $ git rm <文件名>
    $ git commit -m "del <文件名>"

3、添加到远程仓库

  1. 推到远程仓库,配置别名

    $ git push https://***.git master #不配置地址别名的推送方式
    $ git remote add <name> https://***.git #配置远程服务器地址别名
    $ git push <name> master #根据别名推送到仓库
  2. 别人一起开发

    $ git clone https://****.git #从远程仓库上down
    $ git pull <name> master #更新本地仓库

4、版本库

  1. 查看日志

    $ git log #查看日志
    $ git log --pretty=oneline #单行查看日志
  2. 版本切换

    $ git reset --hard HEAD^^^ #从当前指针向前返回三个版本
    $ git reset --hard <版本号> #调到该版本号
    $ git reflog #查看版本干的事情

5、分支管理

  1. 分支操作

    $ git branch #查询当前分支
    $ git branch <wechat> #新建分支
    $ git checkout <wechat> #切换分支
    $ git merge <ali> #在master下合并分支,合并到master
    $ git branch -d <dev> #删除分支
    $ git checkout -b <dev> #创建dev分支并切换到dev分支

6、远程仓库

  1. 远程仓库操作

    $ git remote #查看远程仓库
    $ git remote -v #查看远程仓库地址
    $ git remote remove <lianshou> #删除远程仓库地址别名
    $ git remote rename <旧name> <新name> #修改远程仓库地址别名

7、配置公钥免密登陆

  1. 本地生成公钥私钥

    • SSHLink去github或者码云上找,
    • 生成公钥后也配置下github或者码云等托管仓库
      $ git remote add origin SSHLink #配置SSH链接
      $ ssh-keygen -t rsa -C "your@email" #生成公钥(id_rsa.pub),私钥(id_rsa),一路回车

猜你喜欢

转载自blog.csdn.net/qq_34134278/article/details/78815915
今日推荐