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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章