Git的安装及使用

Git - Downloads https://www.git-scm.com/download/
点进去就自动识别适合你的版本了。
安装很简单:git的安装和配置_百度经验 https://jingyan.baidu.com/article/9f7e7ec0b17cac6f2815548d.html
使用
先推荐一篇详细的教程吧!https://blog.csdn.net/free_wind22/article/details/50967723看完也就懂了。
windows版本装完有bash,gui,cmd三种,我觉得bash挺好用的,按照上面的教程。
摘了一些常用的命令

git init
将当前目录变为git可以管理的本地仓库
向库中添加文件
git add file
提交文件
git commit
git commit -m '提交的说明注释'
git commit只是提交到本地的仓库,远程仓库并无影响
查看状态
git status
查看file的修改内容
git diff file
查看修改的历史记录:
获取到每次commit之后的版本号
git log

这里写图片描述

回退到上次修改的版本
git reset --hard HEAD^
回退到最新版本 
gti reset --hard 版本号
获取到版本号
git reflog

这里写图片描述

将github上的库clone到本地
git clone https://github.com/yourGithub/yourRepository
将本地的库和github上的库进行关联
git remote add origin https://github.com/yourGithub/yourRepository
创建并切换分支
 git checkout -b SpringHibernate
相当于
创建分支
git branch  SpringHibernate 
切换分支
git checkout SpringHibernate
查看当前分支
  git branch
将本上的内容上传到github对应库的SpringHibernate分支上
git push origin SpringHibernate


1,  github上创建一个本地库,yourRepository
2,克隆到本地
git clone https://github.com/yourGithub/yourRepository
(2,
如果想将本地的文件夹直接作为库和远程库进行关联就使用
git remote add origin https://github.com/yourGithub/yourRepository
)
3,创建并切换分支 
git checkout -b newbranch
如果想要删除分支oldbranch使用git branch -d oldbranch
想要删除当前正在使用的分支使用git branch -D newbranch
4,添加我要上传到本地库的文件(将文件添加到暂存区)
git add myfile
add之后想要放弃,撤销使用:git checkout -- myfile
5,将刚才add的文件提交到当前分支上
git commit  -m '文件说明'
如果提交之后想要删除可以在对应目录直接删除文件也可以使用命令:rm myfile
如果又想要恢复删除的文件可以使用git checkout -- myfile
6,将本地仓库中的文件提交到远程库中
git push origin newbranch

(我常用的提交方式是:在github上创建本地库后克隆到本地之后再提交我的文件)

猜你喜欢

转载自blog.csdn.net/flower_CSDN/article/details/80787724