將已經存在的項目提交到gitlab中python
在gitlab中新增用戶jackgit
登陸jack這個git用戶,而後建立倉庫 mxonline
已經寫好了部分功能的項目存放在 D:\>cd D:\python\mxonline\
須要推送到gitlab中
運行git_cmd.exe
# 切換到項目目錄下
D:\>cd D:\python\mxonline\
# 初始化
D:\python\mxonline>git init
Initialized empty Git repository in D:/python/mxonline/.git/
# 加入主分支
D:\python\mxonline>git remote add origin https://gitlab.example.com/jack/mxonline.git
D:\python\mxonline>git add .
warning: LF will be replaced by CRLF in .idea/misc.xml.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in .idea/modules.xml.
The file will have its original line endings in your working directory
# 提交代碼失敗
D:\python\mxonline>git push -u origin master
To https://gitlab.example.com/jack/mxonline.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://gitlab.example.com/jack/mxonline.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.
# 使用帳號密碼的方式,照樣失敗
D:\python\mxonline>git remote set-url origin https://jack:jack2019@gitlab.example.com/jack/mxonline.git
# 最終的解決辦法:
經過查看提示信息,我發現,是由於本地倉庫和遠程倉庫的文件不一致所致,也就是說,github容許你本地倉庫有的東西,遠程倉庫裏沒有,但不容許遠程倉庫有的東西,你本地倉庫沒有。問題找到了,解決辦法就很簡單了,那就是在push以前先同步一下本地倉庫與遠程倉庫的文件。使用如下命令
D:\python\mxonline>git pull --rebase origin master
From https://gitlab.example.com/jack/mxonline
* branch master -> FETCH_HEAD
* [new branch] master -> origin/master
First, rewinding head to replay your work on top of it...
Applying: 'init'
D:\python\mxonline>git push -f origin master
Enumerating objects: 1552, done.
Counting objects: 100% (1552/1552), done.
Delta compression using up to 8 threads
Compressing objects: 100% (1491/1491), done.
Writing objects: 100% (1551/1551), 9.44 MiB | 3.46 MiB/s, done.
Total 1551 (delta 350), reused 0 (delta 0)
remote: Resolving deltas: 100% (350/350), done.
To https://gitlab.example.com/jack/mxonline.git
8c83ef5..5509745 master -> master
至此,本地代碼就推送到了遠程倉庫的master中
# 提示warning: LF will be replaced by CRLF in .idea/misc.xml.
D:\python\mxonline>git add .
warning: LF will be replaced by CRLF in .idea/misc.xml.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in .idea/workspace.xml.
The file will have its original line endings in your working directory
# 解決
D:\python\mxonline>git config --global core.autocrlf false
# 修改代碼後的提交
D:\python\mxonline>git add .
D:\python\mxonline>git commit -m "update readme"
D:\python\mxonline>git -c http.sslVerify=false push origin master
# 標籤
# 查看標籤
D:\python\mxonline>git tag
# 命名標籤
D:\python\mxonline>git tag mxonline20191016 -m "拉分支前的備份"
# 推送標籤
D:\python\mxonline>git push origin mxonline20191016
# 分支的操做
# 查看分支
D:\python\mxonline>git branch
* master
# 建立名爲 dns_manage的分支
D:\python\mxonline>git branch dns_manage
D:\python\mxonline>git branch
dns_manage
* master
# 切換到 dns_manage 分支
D:\python\mxonline>git checkout dns_manage
Switched to branch 'dns_manage'
M .idea/workspace.xml
# 修改代碼,而後提交到分支中,能夠看到git的web界面中就有分支了
D:\python\mxonline>git add .
D:\python\mxonline>git commit -m "add dns_manage readme"
[dns_manage a7efacc] add dns_manage readme
2 files changed, 21 insertions(+), 14 deletions(-)
create mode 100644 apps/dns_manage/dns_readme.md
D:\python\mxonline>git push origin dns_manage
Enumerating objects: 12, done.
Counting objects: 100% (12/12), done.
Delta compression using up to 8 threads
Compressing objects: 100% (7/7), done.
Writing objects: 100% (7/7), 782 bytes | 78.00 KiB/s, done.
Total 7 (delta 5), reused 0 (delta 0)
remote:
remote: To create a merge request for dns_manage, visit:
remote: https://gitlab.example.com/jack/mxonline/merge_requests/new?merge_request%5Bsource_branch%5D=dns_manage
remote:
To https://gitlab.example.com/jack/mxonline.git
* [new branch] dns_manage -> dns_manage
# 能夠從界面中看到新的分支github