版本管理工具-git安装和使用

同版本安装文件和学习笔记,在https://github.com/sunasitA/skillMap.git 下

注册github账号和安装github客户端

  1. https://github.com/注册一个github账号
  2. Windows安装github客户端
    到https://desktop.github.com/ 点击Download for Windows。GitHubDesktopSetup.exe也上传到了本仓库。
  3. 点击exe文件安装,填入1中注册的github账号。

创建一个仓库

  1. 点击 create a new repository on your hard drive 创建一个新仓库skillMap,然后publish
  2. 登陆github web界面可以看到新建的仓库,点击Clone or download按钮拿到仓库地址

Git安装和项目clone

  1. Windows安装git(安装包上传在本仓库)
  2. 打开git bash,设置登陆账号,设置代理
git config –global user.name ‘’
git config –global user.email ‘’
git config –global http.proxy ‘XXX’

clone项目

git clone https://github.com/sunasitA/skillMap.git D:\skillmap

报错:fatal: HttpRequestException encountered.
remote: Repository not found.
fatal: repository ‘https://github.com/sunasitA/skillMap.git/’ not found

原因:skillMap仓库是private的,修改为public即可
修改方法:到github web界面-》setting-》拉到最下面-》修改为public

修改和提交本地文件到远程仓库

  1. 在本地仓库新建多个文件
  2. Git bash提交文件到远程仓库
git add .
git commit –m ‘第一次提交’
git push -u origin master

此处报错:remote: Permission to sunasitA/skillMap.git denied to XXX.

原因电脑记了两个账号,要ssh到另一个,修改.git/cofig中的url

cd 到项目中,编辑 .git/cofig中的url
vim .git/config

[remote “origin”]
url = https://github.com/git的用户名/项目名称
的url改为
url = https://git的用户名@github.com/git的用户名/项目名称
即url = https://[email protected]/sunasitA/skillMap.git
再执行 git push -u origin master
输入账户,即可提交

  1. 查看github网站,所有文件提交成功

撤销commit&push到远程仓库的提交

  1. 修改文件,提交
git add .
git commit -m '这是次恶意提交'
git push origin master
  1. 撤销本次提交
    git log找到到回退到的版本ID,比如这次要回退到c84f39c3f83db5692337a41a1a16bb07693aabfe
    git log
commit e51bb4de709f321c72c4dc8ab348c18665247959 (HEAD -> master, origin/master, origin/HEAD)
Author: sunasitA 
Date:   Fri Aug 23 17:25:55 2019 +0800
    这是次恶意提交

commit c84f39c3f83db5692337a41a1a16bb07693aabfe
Author: sunasitA 
Date:   Fri Aug 23 10:20:13 2019 +0800
    删除临时文件

git reset --hard退回到对应的版本,这边注意–hard会同步回退工作区文件,使用此命令要特别小心

git reset --hard e51bb4de709f321c72c4dc8ab348c18665247959

git log查看log
git log

commit c84f39c3f83db5692337a41a1a16bb07693aabfe (HEAD -> master)
Author: sunasitA 
Date:   Fri Aug 23 10:20:13 2019 +0800
    删除临时文件		  
  1. 强制提交当前版本号
git push origin master –force

找回git reset –hard的版本
对于git reset –hard错误回退的代码,通过下面步骤找回。
(1) git reflog 找到git reset –hard的版本号
(2) git reset –hard (1)的id
(3) 将文件拷贝出来
(4) 替换本地工作区的文件
(5) git add .
git commit –m ‘’
git push origin master

什么是里程碑
完整可用版本的release。

分支开发和合并到master
Mster分支推送了新的没有测试的代码,而已发布的代码中存在一个bug,此时就要在已发布代码上创建一个分支。

  1. 创建一个新分支,切换到新分支
git branch newBranch
git branch –a
git checkout newBranch
  1. 在新分支上进行修改
    直接在本地工作区修改文件,就是在当前分支开发
  2. 提交
git add . 
git commit 
git push origin newBranch
  1. 发布修改了bug的版本
  2. 切换到master分支,查看4的修改没有反应到master分支
  3. 合并现在的代码到master的分支
git merge newBranch
git status
git push origin master
git log

newBranch的修改已经merge到master分支

你可能感兴趣的:(技巧提高)