git使用

130 阅读1分钟

git的使用

1.什么是git

Git 是 Linus Torvalds 为了帮助管理 Linux 内核开发而开发的一个开放源码的分布式版本控制系统。

2.安装git

   1.https://git-scm.com/download/win
   2.下载安装成功
   3.win+R  -> cmd进入
   3.输入git 或 git --version  查看git版本

3.使用git

git config --global user.name "...." ---提交人的信息,方便别人查看

git config --global user.email "" -----注意空格,本人因为空格多次失败

1.git init -- 初始化工程

2.git status -- 查看目前的状态

3.git add . -- 就是将工作区的代码添加到暂存区 .的意思代表 all

4.git commit -m "" -- commit是提交的意思 -m "注释的内容"

5.git log -- 查看版本库中有哪些版本

6.git diff -- 查看提交前后的不同,有+ -标注

7.git reset --hard "" hard后跟一大串字符,输入字符回到之前版本

8.git reflog 同上

9.git branch -- 创建分支

10.git remote --使用远程仓库

11.git clone --克隆远程仓库

4.使用远程仓库?

github,上传github仓库代码 --先注册一个账号
   1. git remote add origin https://github.com/hjyl-cheng/mygittest.git
   2. git push -u origin master

   git remote add origin https://gitee.com/ebonc/mygittest.git
   git remote remove  --去除origin变量 防止冲突
    
   完整的流程开发的代码
   1.git init
   2.git status
   3.git add .
   4.git commit -m ""
   5.git remote add origin https://github.com/hjyl-cheng/mytest2.git
   6.git push -u origin master

5.免密上传代码

 1)在本地生成公私钥
      ssh-keygen -t rsa -- 生成公私钥
    2)将公钥放到github上去
    3)ssh -T git@github.com
   
    使用免密上传步骤
    1)git init
    2)git add .
    3)git commit -m ""
    4)git remote add origin git@github.com:hjyl-cheng/mytest3.git -- 地址是SSH地址,不是http地址!!!
    5)git push origin master