github --- > 多个项目的管理方式

1. 多个项目管理方式

  1. 进入项目根目录: git init

  2. 将当前的项目添加到暂存区中: git add . (注意: 最后有一个点)

  3. 将暂存区的内容放到本地仓库: git commit -m '初始化项目'

  4. 登录github , 新建远程仓库

  5. 在本地添加远程仓库的源: git remote origin https://github.com/Lizhhhh/miniProgram.git

  6. 将本地代码提交到远程: git push -u origin master

1.1 给提交的代码添加标签,并提交到远程

  • 假设现在,我们在本地修改好了代码:
  1. 将代码保存到暂存区 git add .
  2. 暂存到本地: git commit -m '知识点1'
  3. 上标记: git tag 01_知识点1
  4. 通过git tag来查看项目中的标签.
$ git tag
01_知识点1
  • 查看项目中有哪些提交: git log
commit 75c6d6bdfa063322ce728b98ab4dc20724efc02d (HEAD -> master, tag: 01_知识点1)
Author: 栗子好好吃 <[email protected]>
Date:   Sat Feb 15 13:58:23 2020 +0800

    知识点1

commit f98bf38a589ce6c696a844f41a81be9e554714ba (origin/master)
Author: 栗子好好吃 <[email protected]>
Date:   Sat Feb 15 14:41:22 2020 +0800

    初始化项目
  1. 找到项目初始化的id,然后进行版本回退: git reset --hard f98bf38

  2. 此时项目处于初始化的状态.你可以对项目进行修改…

  3. 修改完成后,将新的代码提交到本地:git add . --> git commit -m '知识点2' --> git tab 02_知识点2

  4. 此时: git tag, 当前的代码仅在本地,而在远程中没有.下面需要将tags推到远程中

$ git tag
01_知识点1
02_知识点2
  1. git push --tags
$ git push --tags
Enumerating objects: 14, done.
Counting objects: 100% (14/14), done.
Delta compression using up to 8 threads
Compressing objects: 100% (10/10), done.
Writing objects: 100% (10/10), 869 bytes | 434.00 KiB/s, done.
Total 10 (delta 6), reused 0 (delta 0)
remote: Resolving deltas: 100% (6/6), completed with 2 local objects.
To https://github.com/Lizhhhh/miniProgram.git
 * [new tag]         01_知识点1 -> 01_知识点1
 * [new tag]         02_知识点2 -> 02_知识点2
  1. 此时可以在git远程仓库中的Branch中找到对应的tags.来完成项目的远程拷贝

1.2 从远程将项目拷贝下来

  1. 登录远程仓,找到克隆的地址: https://github.com/Lizhhhh/miniProgram.git

  2. 将远程仓库的代码拷贝到本地: git clone

$ git clone https://github.com/Lizhhhh/miniProgram.git
Cloning into 'miniProgram'...
remote: Enumerating objects: 26, done.
remote: Counting objects: 100% (26/26), done.
remote: Compressing objects: 100% (16/16), done.
remote: Total 26 (delta 8), reused 25 (delta 7), pack-reused 0
Unpacking objects: 100% (26/26), done.
  1. 现在假设想查看tag 01_知识点1的代码,可以在命令行输入:git checkout 01_知识点1
$ git checkout 01_知识点1
Note: checking out '01_知识点1'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

HEAD is now at 4e8281e 知识点1
M       app.json
M       project.config.json
  1. 现在假设想查看tag 02_知识点2的代码,可以在命令行输入:git checkout 02_知识点2
$ git checkout 02_知识点2
Previous HEAD position was 4e8281e 知识点1
HEAD is now at 75c6d6b 知识点2
M       app.json
M       project.config.json
发布了228 篇原创文章 · 获赞 41 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/piano9425/article/details/104328316