一、需求
本地有一個微信小程式的專案原始碼,只是資料夾的形式,包括一些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使用者名稱和密碼
[email protected] MINGW64 /d/SmallAPP
$ git config --global user.name "wangxuejing"
[email protected] MINGW64 /d/SmallAPP
$ git config --global user.email "[email protected]"
訪問遠端的GitLab,並克隆下來()
[email protected] 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資料夾)
[email protected] MINGW64 /d/SmallAPP
$ cd SmallAPP
新建一個readme檔案
[email protected] MINGW64 /d/SmallAPP/SmallAPP (master)
$ touch README.md
新增到本地倉庫
[email protected] MINGW64 /d/SmallAPP/SmallAPP (master)
$ git add README.md
提交到遠端倉庫
[email protected] 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
[email protected] 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『.
切換到我們專案所在的目錄
[email protected] MINGW64 /d/SmallAPP/SmallAPP (master)
$ cd /d/SmallAPP
初始化Git資源庫
[email protected] MINGW64 /d/SmallAPP
$ git init
Initialized empty Git repository in D:/SmallAPP/.git/
把本地專案新增到GitLab的遠端地址
[email protected] MINGW64 /d/SmallAPP (master)
$ git remote add origin http://IP:3680/wangxuejing/SmallAPP.git
[email protected] 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 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.
[email protected] 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這裡報錯了
[email protected] 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,並把他們接到更新後的版本庫之中。
[email protected] 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發現執行成功
[email protected] 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『.
[email protected] MINGW64 /d/SmallAPP (master)
$
驗證我們去GitLab檢視,如下圖所示