今天以 git 结合 码云 进行介绍。
Git
Git是一个免费的开源 分布式版本控制系统,旨在快速高效地处理从小型到大型项目的所有内容
Git 易于学习, 占地面积小,具有闪电般的快速性能。它具有Subversion,CVS,Perforce和ClearCase之类的SCM工具,具有廉价的本地分支,方便的暂存区域和 多个工作流等功能。
码云
码云(gitee.com)是 OSCHINA.NET 推出的代码托管平台,支持 Git 和 SVN,提供免费的私有仓库托管。目前已有超过 500 万的开发者选择码云。
一、安装及配置
1.下载git:
从git官网下载安装、或者从软件管家中安装。
2.配置:
git config --global user.name 'abc'
git config --global user.email '44xxxx712@qq.com'
3.加入项目组:
把你的git
邮箱给到你的相关负责,让他把你加进去。
二、拉取代码及创建分支
1.新建文件夹,在该文件夹中打开git
2.拉取代码:
git clone https://gitee.com/luoxxxx/todo-list.git
3.进入该项目 (tab辅助输入完整项目名)
git cd todo-list
4.查看
git branch --list
查看当前本地的所有的分支名
pwd
查看当前位置
git branch test
新建名为test的分支名(此时远程仓库该新分支暂不可见)
git checkout test
切换分支
5.提交修改后的代码到test
分支
git add --all
git commit -m '修改注释'
git push origin test
三、分支合并及冲突处理
冲突产生的根本原因是,多个人修改了同一行代码。
举个例子:把
test
分支合并到master
分支
git checkout test
git pull
git checkout master
git merge test
如果出现冲突,去到编辑中找到对就的代码文件,进行冲突合并(用谁的代码)
git add .
git commit -m '
合并test分支'
git push origin master
五、版本回退
git log
git reset --hard a65e8b65020221ef3db94497c4c19d0ae421b7c6
六、其它
git remote show origin
查看远程仓库信息
七、问题及解决
1. git 提示 fatal: remote origin already exists
1、先删除远程 Git 仓库
$ git remote rm origin
2、再添加远程 Git 仓库
$ git remote add origin https://github.com/zxxxxxo/ToDoList.git
- 提示如下
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://gitee.com/luozhian/todo-list.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
出现这个问题是因为github中的README.md文件不在本地代码目录中,可以通过如下命令进行代码合并(考虑看下自己代码)
git pull --rebase origin master