
1.Git 命令
非系统盘非中文路径,建立一个文件夹SpringStudy,如E:\SpringStudy
cd : 进入相应目录。
git init : 将该目录初始化为一个git仓库。

2.向仓库添加文件、提交文件
git add 文件名:把文件加入git仓库。
出现 warning 解决方案:git config core authcr If true
git commit -m "说明文字":把文件提交到仓库
注意:所有文件必须先 add 再 commit !!!!

3 创建SSH Key
在用户主目录下(打开命令行窗口的默认路径),看看有没有.ssh目录,如果有,再看看这个目录下有没有id_rsa
和id_rsa.pub
这两个文件,如果已经有了,可直接跳到下一步。如果没有,打开Shell(Windows下打开Git Bash),创建SSH Key:ssh-keygen -t rsa -C "youremail@example.com",一路回车键,效果如图。

然后就可以用记事本打开id_rsa.pub文件了
4 在GitHub中加入SSH Key
登录GitHub,点击个人头像,选择Settings,在“SSH And GPG keys”页面,点击“New SSH Key”按钮,在Key文本框粘贴id_rsa.pub文件的内容:
完成后如图

5创建一个新仓库
在GitHub创建一个new Spring的仓库


6 设置远程库、把本地库的所有内容推送到远程库上
在本地的git仓库运行命令
git remote add origin git@github.com:RuiLinZhu/new-Spring.git
远程库的名字是origin,这是Git默认的叫法,也可以改成别的,但是origin这个名字一看就知道是远程库。后面是使用Git协议,注意账号和仓库名的修改
git push -u origin master
注意:
一定要本地仓库先提交,然后才能向远程仓库push
如果push失败,应该是远程库版本比本地库新,应该用git pull先把远程库拉下来,然后再push
总结
- git:查看系统有没有安装Git
- 设置全局属性,用户名和邮箱
- git config --global user.name "Your Name"
- git config --global user.email “email@example.com”
- git init:创建版本库
- git add hello.txt:将文件添加到临时区
- git commit -m “create hello.txt file”:把文件提交到仓库
- git status:查看当前的Git仓库状态
- git log:查看从近到远的提交日志
- git log --pretty=online:简略显示
- git reset --hard HEAD:回退到上一版本
- git reset --hard commit_id:穿梭到指定版本号的版本
- git rm hello.txt:删除文件
注意:
- commit之前一定要先add
- 可以进行文件夹所有文件提交,以及指定提交某些文件
网友评论