一、需求
本地有一个微信小程序的项目源码,只是文件夹的形式,包括一些js和一些页面,想把这个文件夹用GitLab管理,于是就需要把本地文件夹push到服务器的GitLab上面
二、操作
2.1:命令来自于哪里?
在GitLab新建一个Project的时候,默认会给出如下的命令行指令,如下图所示,我们也首先创建一个项目在GitLab中
完整的指令示例如下,只需要按步骤操作即可
Command line instructions
Git global setup
git config --global user.name "wangxuejing"
git config --global user.email "[email protected]"
Create a new repository
git clone http://10.10.1.36/wangxuejing/test-add.git
cd test-add
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master
Existing folder
cd existing_folder
git init
git remote add origin http://10.10.1.36/wangxuejing/test-add.git
git add .
git commit -m "Initial commit"
git push -u origin master
Existing Git repository
cd existing_repo
git remote rename origin old-origin
git remote add origin http://10.10.1.36/wangxuejing/test-add.git
git push -u origin --all
git push -u origin --tags
2.2:执行命令和命令详解
在一个目录中点击Git Bush Here进入Git的命令行操作窗口,如下图所示
接下来开始详细解释----------------------------------------------------------------------------------------------------------------------------------------------------
设置Git用户名和密码
king@KING MINGW64 /d/SmallAPP
$ git config --global user.name "wangxuejing"
king@KING MINGW64 /d/SmallAPP
$ git config --global user.email "[email protected]"
访问远程的GitLab,并克隆下来()
king@KING MINGW64 /d/SmallAPP
$ git clone http://IP:3680/wangxuejing/SmallAPP.git(需要输入GitLab的用户名和密码)
Cloning into 'SmallAPP'...
warning: You appear to have cloned an empty repository.(这里可以无视,因为我们创建的就是一个空project)
切换到我们本地仓库所在的目录(因为我们是在项目根目录操作的,所以默认把GitLab的项目克隆到了根目录下面的SmallAPP文件夹)
king@KING MINGW64 /d/SmallAPP
$ cd SmallAPP
新建一个readme文件
king@KING MINGW64 /d/SmallAPP/SmallAPP (master)
$ touch README.md
添加到本地仓库
king@KING MINGW64 /d/SmallAPP/SmallAPP (master)
$ git add README.md
提交到远程仓库
king@KING MINGW64 /d/SmallAPP/SmallAPP (master)
$ git commit -m "add README"
[master (root-commit) 0689a97] add README
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 README.md
设置分支为主分支master
king@KING MINGW64 /d/SmallAPP/SmallAPP (master)
$ git push -u origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 217 bytes | 217.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To http://IP:3680/wangxuejing/SmallAPP.git
* [new branch] master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
切换到我们项目所在的目录
king@KING MINGW64 /d/SmallAPP/SmallAPP (master)
$ cd /d/SmallAPP
初始化Git资源库
king@KING MINGW64 /d/SmallAPP
$ git init
Initialized empty Git repository in D:/SmallAPP/.git/
把本地项目添加到GitLab的远程地址
king@KING MINGW64 /d/SmallAPP (master)
$ git remote add origin http://IP:3680/wangxuejing/SmallAPP.git
king@KING MINGW64 /d/SmallAPP (master)
$ git add .
warning: adding embedded git repository: SmallAPP
hint: You've added another git repository inside your current repository.
hint: Clones of the outer repository will not contain the contents of
hint: the embedded repository and will not know how to obtain it.
hint: If you meant to add a submodule, use:
hint:
hint: git submodule add <url> SmallAPP
hint:
hint: If you added this path by mistake, you can remove it from the
hint: index with:
hint:
hint: git rm --cached SmallAPP
hint:
hint: See "git help submodule" for more information.
warning: LF will be replaced by CRLF in app.js.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in app.json.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in app.wxss.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in pages/index/index.js.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in pages/index/index.wxml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in pages/index/index.wxss.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in pages/logs/logs.js.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in pages/logs/logs.json.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in pages/logs/logs.wxml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in pages/logs/logs.wxss.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in project.config.json.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in utils/util.js.
The file will have its original line endings in your working directory.
king@KING MINGW64 /d/SmallAPP (master)
$ git commit -m "Initial commit"
[master (root-commit) 9c249d4] Initial commit
18 files changed, 794 insertions(+)
create mode 160000 SmallAPP
create mode 100644 app.js
create mode 100644 app.json
create mode 100644 app.wxss
create mode 100644 pages/index/index.js
create mode 100644 pages/index/index.wxml
create mode 100644 pages/index/index.wxss
create mode 100644 pages/libs/qqmap-wx-jssdk.js
create mode 100644 pages/logs/logs.js
create mode 100644 pages/logs/logs.json
create mode 100644 pages/logs/logs.wxml
create mode 100644 pages/logs/logs.wxss
create mode 100644 pages/test/test.js
create mode 100644 pages/test/test.json
create mode 100644 pages/test/test.wxml
create mode 100644 pages/test/test.wxss
create mode 100644 project.config.json
create mode 100644 utils/util.js
push所有文件到远程的GitLab这里报错了
king@KING MINGW64 /d/SmallAPP (master)
$ git push -u origin master
To http://IP:3680/wangxuejing/SmallAPP.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'http://IP:3680/wangxuejing/SmallAPP.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.
这个问题是因为远程库与本地库不一致造成的,那么我们把远程库同步到本地库就可以了。
使用指令
git pull --rebase origin master
这条指令的意思是把远程库中的更新合并到本地库中,–rebase的作用是取消掉本地库中刚刚的commit,并把他们接到更新后的版本库之中。
king@KING MINGW64 /d/SmallAPP (master)
$ git pull --rebase origin master
warning: no common commits
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From http://IP:3680/wangxuejing/SmallAPP
* branch master -> FETCH_HEAD
* [new branch] master -> origin/master
First, rewinding head to replay your work on top of it...
warning: unable to rmdir 'SmallAPP': Directory not empty
Applying: Initial commit
然后再次执行git push -u origin master发现执行成功
king@KING MINGW64 /d/SmallAPP (master)
$ git push -u origin master
Counting objects: 25, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (21/21), done.
Writing objects: 100% (25/25), 8.07 KiB | 826.00 KiB/s, done.
Total 25 (delta 0), reused 0 (delta 0)
To http://IP:3680/wangxuejing/SmallAPP.git
0689a97..3735d44 master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
king@KING MINGW64 /d/SmallAPP (master)
$
验证我们去GitLab查看,如下图所示