Git/Gitlab抓取,提交,库的迁移/备份及回收/重命名

1.gitlab基本概念

GitLab是一个基于 Web 的 Git 仓库管理工具,且具有wiki 和 issue 跟踪功能。GitLab 由 GitLab Inc. 开发,使用开源许可证。
GitLab 由乌克兰程序员 Dmitriy Zaporozhets 和 Valery Sizov 开发。它由 Ruby 写成。后来,一些部分用Go语言重写。截止2016年12月,该公司有150名团队成员,以及1400多名开源贡献者。 GitLab被 IBM,Sony,Jülich Research Center,NASA,Alibaba,Invincea,O’Reilly Media,Leibniz-Rechenzentrum (LRZ),CERN,SpaceX 等组织使用。

2.gitlab库创建

Git/Gitlab抓取,提交,库的迁移/备份及回收/重命名

点击“New project”

Git/Gitlab抓取,提交,库的迁移/备份及回收/重命名

按照上面步骤,最后点击“Create project”

3.文件提交
在客户端上(mac本的远程终端上)进行如下操作:
Git global setup
git config --global user.name "wtf"
git config --global user.email "wtf@linuxmi.com"
git clone ssh://git@gitlab.linuxmicom:19234/linux/linux_datagrand.git
cd linux_datagrand
echo "this is a test file."  >  wtf.txt
cat wtf.txt
this is a test file !
git add .
git commit -m "add a file named wtf.txt"
git push -u origin master
这样就可以将客户端文件上传到gitlab的仓库里了。

4.文件抓取
如果我在gitlab上linux_datagrand.git这个仓库里进行如下操作:
添加shiyan.txt和目录test这两个文件,那么我在客户端应该怎么操作才能将新增的文件“拉取”到本地呢?
cd linux_datagrand
git pull 或 git pull --rebase origin master
说明:建议使用git pull,原因我会在下文说明。
cat linux_datagrand
wtf.txt  shiyan.txt  test

5.在存在的文件下进行文件递交
如果我在终端上有个目录文件existing_folder,里面的文件需要递交至git库,而你又不想cp到目标库再push,那么你可以这样做:
cd existing_folder
git init
git remote add origin ssh://git@gitlab.linuxmi.com:19234/linux/linux_datagrand.git
git add .
git commit -m "Initial commit"
在push之前先进性pull操作:
git pull --rebase origin master
如果不进行pull这一步,会报如下错误:
error: failed to push some refs to git。
然后:
git push -u origin master

6.库的迁移或备份
##如我想把linux_datagrand.git这个库里的文件迁移至linuxmi.git这个新库中,要求如下:
(1)迁移的时候就要考虑到已有的分支;
(2)保留以前的提交记录;
(3)不要把本地的代码直接提交到gitLab,这样以前提交的记录和分支就都没有了。
##操作如下:
git clone ssh://git@gitlab.linuxmicom:19234/linux/linux_datagrand.git
cd linux_datagrand
ls
name.txt  shiyan.txt
##查看当前的远程仓库:
git remote -v
origin  ssh://git@gitlab.linuxmicom:19234/linux/linux_datagrand.git (fetch)
origin  ssh://git@gitlab.linuxmicom:19234/linux/linux_datagrand.git (push)
##添加linuxmi.git这个远程仓库
git remote add test ssh://git@gitlab.linuxmicom:19234/linux/linuxmi.git
说明:添加远程仓库的格式:
git remote add  仓库名字  [仓库地址]
##查看当前的远程仓库:
git remote -v
origin  ssh://git@gitlab.linuxmicom:19234/linux/linux_datagrand.git (fetch)
origin  ssh://git@gitlab.linuxmicom:19234/linux/linux_datagrand.git (push)
test    ssh://git@gitlab.linuxmicom:19234/linux/linuxmi.git (fetch)
test    ssh://git@gitlab.linuxmicom:19234/linux/linuxmi.git (push)
##把本地的分支push到远程仓库
git push -u test master
这个时候有报错,内容如下:
error: failed to push some refs to 'ssh://git@gitlab.linuxmicom:19234/linux/linuxmi.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.
##解决方法:
(1)由于GitLab一些分支默认被保护,仅仅拥有master级别的用户才能提交到保护分支,而且master分支默认是保护分支,其他用户需要通过合并issue请求来提交上去。所以我们先关闭这个master分支保护: Project: "Settings" -> "Repository" -> “Protected Branches(Expand)”  -> "Unprotect"。
(2)使用命令:git push -f test master
所以把本地的分支push到远程仓库命令:
git push -f test master
##这个时候,我们已经把linux_datagrand.git这个库里的文件迁移至linuxmi.git这个新库中了。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/12575.html