项目目录结构设计与Git远程仓库的建立
来自CloudWiki
目录
项目目录结构
Git远程仓库
- 在码云上新建一个组织,
- 在组织上新建一个项目
Git本地仓库
要把远程项目克隆到本地(git clone),我们首先需要一个SSH KEY
生成SSH KEY
第1步:创建SSH Key。在windows下查看[c盘->用户->自己的用户名->.ssh]下是否有id_rsa、id_rsa.pub文件,如果没有需要手动生成。 打开git bash,在控制台中输入以下命令。 1
$ ssh-keygen -t rsa -C "youremail@example.com"
密钥类型可以用 -t 选项指定。如果没有指定则默认生成用于SSH-2的RSA密钥。这里使用的是rsa。
同时在密钥中有一个注释字段,用-C来指定所指定的注释,可以方便用户标识这个密钥,指出密钥的用途或其他有用的信息。所以在这里输入自己的邮箱或者其他都行。
输入完毕后程序同时要求输入一个密语字符串(passphrase),空表示没有密语。接着会让输入2次口令(password),空表示没有口令。3次回车即可完成当前步骤,此时[c盘>用户>自己的用户名>.ssh]目录下已经生成好了。
thinkpad@DESKTOP-LN2H42N MINGW64 ~ $ ls ~/.ssh/ id_rsa id_rsa.pub known_hosts thinkpad@DESKTOP-LN2H42N MINGW64 ~ $ cat ~/.ssh/id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCwXh9DNpLTcFd6izUzPleoZBzaGQmOfV9rKlDgQBNPIO+I+rSDPRtAZ/d30JjLDc+nomgCg8W+U8vptq4et0n6IpQGufQG2faN4OL0bo6syueOQ3T1GgqoQvXUJjYRTIWKeQYLvSfbf9XO7b0sXK6xO4fVLtWeNah6qveOES5qJKznfboz/60j5wz4RLsvtJO/vG6946wyLZa7VmXIw+jZuc1MMnvvpgKLQyKBi18HHXxs4J5L/eAKWU5coD6TBVR4mtvddYC7FE4Dl+l6gmKNNKcUM1QBK/T91lWCd6NRuNK5Y4sqkxd5f2rNp9fbhU+lzaBtoE2O1e+L48P6dKfB maxin5452@163.com
粘贴公钥
将此公钥作为个人公钥粘贴到码云上
(个人设置 -》 安全设置 -》 SSH公钥)
连接远程仓库
thinkpad@DESKTOP-LN2H42N MINGW64 ~ $ mkdir mmall thinkpad@DESKTOP-LN2H42N MINGW64 ~ $ cd mmall thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall $ mkdir doc thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall $ cd doc 将项目从远程克隆到本地: thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall/doc $ git clone git@gitee.com:happymmall_shangzhi/mmall_fe.git Cloning into 'mmall_fe'... Warning: Permanently added 'gitee.com,218.11.0.86' (ECDSA) to the list of known hosts. remote: Enumerating objects: 3, done. remote: Counting objects: 100% (3/3), done. remote: Compressing objects: 100% (2/2), done. remote: Total 3 (delta 0), reused 0 (delta 0) Receiving objects: 100% (3/3), done. thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall/doc $ ls mmall_fe/ thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall/doc $ cd mmall_fe thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall/doc/mmall_fe (master) $ ls README.md
从本地上传文件到远程
thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall/doc/mmall_fe (master) $ cd .. thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall/doc $ ls mmall_fe/ thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall/doc $ rm -rf mmall_fe/ thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall/doc $ ls thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall/doc $ mkdir mmall-fe thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall/doc $ ls mmall-fe/ thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall/doc $ cd mmall-fe/ thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall/doc/mmall-fe $ touch test.html thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall/doc/mmall-fe $ ls test.html thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall/doc/mmall-fe $ git init Initialized empty Git repository in C:/Users/thinkpad/mmall/doc/mmall-fe/.git/ thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall/doc/mmall-fe (master) $ ls -al total 4 drwxr-xr-x 1 thinkpad 197121 0 10月 3 21:15 ./ drwxr-xr-x 1 thinkpad 197121 0 10月 3 21:15 ../ drwxr-xr-x 1 thinkpad 197121 0 10月 3 21:15 .git/ -rw-r--r-- 1 thinkpad 197121 0 10月 3 21:15 test.html 把当前的文件夹和远程的git文件夹对应起来: thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall/doc/mmall-fe (master) $ git remote add origin git@gitee.com:happymmall_shangzhi/mmall_fe.git 把远程的git分支拉下来: thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall/doc/mmall-fe (master) $ git pull origin master remote: Enumerating objects: 3, done. remote: Counting objects: 100% (3/3), done. remote: Compressing objects: 100% (2/2), done. remote: Total 3 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (3/3), done. From gitee.com:happymmall_shangzhi/mmall_fe * branch master -> FETCH_HEAD * [new branch] master -> origin/master thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall/doc/mmall-fe (master) $ git status On branch master Untracked files: (use "git add <file>..." to include in what will be committed) test.html nothing added to commit but untracked files present (use "git add" to track) 把这个文件先追踪上来: thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall/doc/mmall-fe (master) $ git add . 将改动提交给本地代码库: thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall/doc/mmall-fe (master) $ git commit -am 'test' [master 4009ffd] test 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test.html 将代码提交到远程: thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall/doc/mmall-fe (master) $ git push --set-upstream origin master Counting objects: 3, done. Delta compression using up to 4 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 264 bytes | 264.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0) remote: Powered by Gitee.com To gitee.com:happymmall_shangzhi/mmall_fe.git 5323f84..4009ffd master -> master Branch master set up to track remote branch master from origin. thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall/doc/mmall-fe (master)
配置gitignore
这个文件的作用是设定哪些文件git可以忽略。
thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall/doc/mmall-fe (master) $ ls README.md test.html thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall/doc/mmall-fe (master) $ rm test.html thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall/doc/mmall-fe (master) $ vi .gitignore thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall/doc/mmall-fe (master) $ cat .gitignore .DS_Store /node_modules/ /dist/ thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall/doc/mmall-fe (master) $ git status On branch master Your branch is up-to-date with 'origin/master'. Changes not staged for commit: (use "git add/rm <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) deleted: test.html Untracked files: (use "git add <file>..." to include in what will be committed) .gitignore no changes added to commit (use "git add" and/or "git commit -a") thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall/doc/mmall-fe (master) $ git add . warning: LF will be replaced by CRLF in .gitignore. The file will have its original line endings in your working directory. thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall/doc/mmall-fe (master) $ git ca 'first initial' [master 277836c] first initial 2 files changed, 4 insertions(+) create mode 100644 .gitignore delete mode 100644 test.html thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall/doc/mmall-fe (master) $ git ps Counting objects: 3, done. Delta compression using up to 4 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 305 bytes | 101.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0) remote: Powered by Gitee.com To gitee.com:happymmall_shangzhi/mmall_fe.git 4009ffd..277836c master -> master thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall/doc/mmall-fe (master) $ ls README.md thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall/doc/mmall-fe (master) $ ls -al total 13 drwxr-xr-x 1 thinkpad 197121 0 10月 3 21:29 ./ drwxr-xr-x 1 thinkpad 197121 0 10月 3 21:15 ../ drwxr-xr-x 1 thinkpad 197121 0 10月 3 21:33 .git/ -rw-r--r-- 1 thinkpad 197121 33 10月 3 21:29 .gitignore -rw-r--r-- 1 thinkpad 197121 939 10月 3 21:19 README.md thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall/doc/mmall-fe (master) $ touch .DS_Store thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall/doc/mmall-fe (master) $ ls README.md thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall/doc/mmall-fe (master) $ ls -al total 13 drwxr-xr-x 1 thinkpad 197121 0 10月 3 21:35 ./ drwxr-xr-x 1 thinkpad 197121 0 10月 3 21:15 ../ -rw-r--r-- 1 thinkpad 197121 0 10月 3 21:35 .DS_Store drwxr-xr-x 1 thinkpad 197121 0 10月 3 21:33 .git/ -rw-r--r-- 1 thinkpad 197121 33 10月 3 21:29 .gitignore -rw-r--r-- 1 thinkpad 197121 939 10月 3 21:19 README.md thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall/doc/mmall-fe (master) $ git status On branch master Your branch is up-to-date with 'origin/master'. nothing to commit, working tree clean
创建分支
git开发的一个习惯是不在master上开发,
所以我们需要切分到一个分支来开发。
thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall/doc/mmall-fe (master) $ git status On branch master Your branch is up-to-date with 'origin/master'. nothing to commit, working tree clean thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall/doc/mmall-fe (master) 创建分支: $ git checkout -b mmall_v1.0 Switched to a new branch 'mmall_v1.0' thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall/doc/mmall-fe (mmall_v1.0) $ git branch master * mmall_v1.0 thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall/doc/mmall-fe (mmall_v1.0) $ ls README.md thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall/doc/mmall-fe (mmall_v1.0) $ git status On branch mmall_v1.0 nothing to commit, working tree clean thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall/doc/mmall-fe (mmall_v1.0) $ mkdir src thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall/doc/mmall-fe (mmall_v1.0) $ cd src/ thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall/doc/mmall-fe/src (mmall_v1.0) $ mkdir view page service thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall/doc/mmall-fe/src (mmall_v1.0) $ ls page/ service/ view/ thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall/doc/mmall-fe/src (mmall_v1.0) $ mkdir util image thinkpad@DESKTOP-LN2H42N MINGW64 ~/mmall/doc/mmall-fe/src (mmall_v1.0) $