从svn迁移到git

引言

公司项目之前一直是用老旧的svn,现在,公司搞了gitLab,于是,开始将代码从svn迁移到git上。

章节一

  1. 新建一个文件夹,打开git,初始化一下:git init,作为本地仓库;

  2. 将svn的代码clone到本地仓库;

  3. git remote add orignin xxx(git远程仓库地址)

  4. 打开AS 将本地仓库当前的代码add VCS,然后在commit

  5. 在push之前,先进行pull拉取一下git线上代码,这时候,会出现master has no tracked branch这个问题,原因是git不知道要从哪个远程分支更新代码,所以需要设置一下,git branch --set-upstream-to=origin/BranchName 即可。直接在git上,或者在AS的Termial上敲写同样的命令行。

  6. 接下来push会出现refusing to merge unrelated histories的错误,原因是两个仓库不同而导致的,需要在后面加上–allow-unrelated-histories进行允许合并,即可解决问题。

  7. 出现这个问题:
    refusing to merge unrelated histories
    解决方案:
    –allow-unrelated-histories


出现这个问题:
master has no tracked branch
解决方案:
git branch --set-upstream-to=origin/BranchName(其中BranchName为对应的分支名称)
但是这个方案不行,给出来这个提示
F:\aa\remove>git branch --set-upstream-to=origin/dev_3.5.1

error: the requested upstream branch 'origin/dev_3.5.1' does not exist
hint: 
hint: If you are planning on basing your work on an upstream
hint: branch that already exists at the remote, you may need to
hint: run "git fetch" to retrieve it.
hint: 
hint: If you are planning to push out a new local branch that
hint: will track its remote counterpart, you may want to use
hint: "git push -u" to set the upstream config as you push.

于是依照它给的提示,尝试进行了push操作:
依旧不行,给出了这个提示:
F:\aa\remove>git push -u origin dev_3.5.1

error: src refspec dev_3.5.1 does not match any
error: failed to push some refs to 'origin'

分析出现 **failed to push some refs to ‘origin’**这个问题
出现错误的主要原因是github中的README.md文件不在本地代码目录中
解决方案:
可以通过如下命令进行代码合并【注:pull=fetch+merge]
git pull --rebase origin BranchName(其中BranchName为对应的分支名称)
接下来有出现了新的错误提示:

fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

意思就是:
fatal:“origin”似乎不是git存储库
致命:无法从远程存储库读取。
请确保您拥有正确的访问权限
并且存储库存在。
首先,排查掉不是git存储库以及不存在的问题;然后,排查了不能访问的权限。

于是找另外一个解决方案:
git pull origin master --allow-unrelated-histories 解决
这条语句执行成功了。
另一个解决方案是:
目前,我一直是pull到自己新建的分支上,避免对master造成影响。现在尝试一下直接pull和push到master上看看。
排查一下是否是这个原因造成。
执行了push操作之后,给出了这个错误提示:
GitLab: You are not allowed to push code to protected branches on this project.
error: failed to push some refs to XXX
原因排查是主管理员限制了master分支我们没办法直接push上去。

解决方案:一个是重新搞一个本地仓库,然后拉取,然后切换到自己从master中新拉的feature分支来,再做操作————见章节2,重新梳理!


有一个小问题是:
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in
原因:
LF和CRLF其实都是换行符,但是不同的是,LF是linux和Unix系统的换行符,CRLF是window 系统的换行符。这就给跨平台的协作的项目带来了问题,保存文件到底是使用哪个标准呢? git为了解决这个问题,提供了一个”换行符自动转换“的功能,并且这个功能是默认处于”自动模式“即开启状态的。
这个换行符自动转换会把自动把你代码里 与你当前操作系统不相同的换行的方式 转换成当前系统的换行方式(即LF和CRLF 之间的转换),这样一来,当你提交代码的时候,即使你没有修改过某个文件,也被git认为你修改过了,从而提示"LF will be replaced by CRLF in"
解决方案:
最简单的一种办法就是把自动转换功能关掉即可。
输入命令:
git config core.autocrlf false (仅对当前git仓库有效)
#提交检出均不转换
git config --global core.autocrlf false (全局有效,不设置推荐全局)

refer:https://www.jianshu.com/p/450cd21b36a4
目前,这个并不是造成合并不到远程分支的原因,因此,暂时先不管这个问题。

章节二

  1. 新建一个文件夹,打开git,初始化一下:git init,作为本地仓库;
  2. 将svn的代码clone到本地仓库;
  3. git remote add orignin xxx(git远程仓库地址)
  4. git pull origin master --allow-unrelated-histories (拉取远程代码)
  5. AS fetch远程代码,获取到对应的远程分支
  6. 切换到自己新建的feature分支
  7. 将从svn clone下来的 Unversioned Files文件 执行 Add VCS 操作(文件有点多,需要点时间跑)
  8. commit,然后push一下。打完收工!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值