参考:http://www.youkuaiyun.com/article/a/2017-05-25/15928190
svn:自己搭建的
git:码云
工具:git-bash (unix shell)
命令顺序
安装好git工具后,创建一个文件夹test,第一次:鼠标右键--Git Bash Here 进入命令行
1>$ git init 初始化文件夹为git库
2>$ git svn clone svn://此处为ip地址/项目路径 举例:git svn clone svn://127.0.0.1/project/trunk/test-admin
输入后,
第一次:需要输入本机windows系统的登录密码
第二次:输入svn帐号
第三次:输入svn密码
根据项目大小会把所有提交文件都进行下载,过程略久
下载好后,在码云上建立项目 test-admin 使用Readme文件初始化这个项目(这个选项要去掉)
创建好后,点项目名,进入项目中,“克隆/下载” 可得到下载地址:https://git.oschina.net/xxxxx/test-admin.git
在这里要注意,在test目录的下一级 test-admin 中操作,第二次:鼠标右键--Bash Here(不然传到git服务器里面的只会是git子项目,无法直接显示、提交代码)
test(在test文件夹内操作:是第一次)
——.git
——test-admin (在test-admin内操作:是第二次)
—————— .git
—————— pom.xml
——————test-admin-web
——————test-admin-core
(或者使用 git log 检测能否看到,项目之前的提交记录,以此来判断 操作是否正确)
3>$ git remote add origin https://git.oschina.net/xxxxx/test-admin.git 添加远端库地址 设定名称为origin
添加成功没有提示的,所以看下是否成功
$ git remote -v
origin https://git.oschina.net/xxxxx/test-admin.git (fetch)
origin https://git.oschina.net/xxxxx/test-admin.git (push)
是成功的!继续
此处如果添加错误:使用命令 git remote remove origin 即可删除名为origin的远端库
git pull
然后遇到报错:
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> master
git push
报错:
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin master
个人猜测:远端库是刚初始化的,还没有建立分支
4>$ git push -u origin master 代码提交成功 搞定了
此时再用 git push 或者 git pull 命令都不会报错了
如果前创建项目时:默认勾选了“用Readme文件初始化这个项目”,会报错
To https://git.oschina.net/zx1323/test.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://git.oschina.net/zx1323/test.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.
4>$ git pull --rebase origin master 获取远端分支,合并
5>$ git push origin master 推送到远端
收工!