---
# System prepended metadata

title: github git 操作流程
tags: [git, github]

---

# github git 操作流程
> 檢查狀態：git status
> 加入索引：git add .
> 提交更新：git commit -m '修改記錄'
> 查詢記錄：git log

# local 端 init: 
```
git init -b main
Initialized empty Git repository in C:/develop/hch_ocr/.git/
```
### 建立及編輯 .gitignore
```
work/
weights/
VerifyKey.exe
VerifyKey.pyc
__pycache__/
```
### git status 觀察
```
git status
On branch main
No commits yet
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        .gitignore
        README.md
        config/
        data_loader/
        dbnmodels/
        drcmodels/
        hch_ocr.py
        hch_ocr.pyc
        lib/
        license
        post_processing/
        py_to_pyc.py
        py_to_pyc.pyc
        utils/

nothing added to commit but untracked files present (use "git add" to track)
```
### git add . (. 表示全部)

### git status
```
git status
On branch main
No commits yet
Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
        new file:   .gitignore
        new file:   README.md
        new file:   config/icdar2015_resnet18_FPN_DBhead_polyLR.yaml
        new file:   config/ocrdebug.py 
        ...
```
### git commit -m '修改記錄'
```
git commit -m "init repo commit"
[main (root-commit) 4867f95] init repo commit
 71 files changed, 2934 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 README.md
 ...
```
### git log
```
git log
commit 4867f955... (HEAD -> main)
Author: Richard Chiu <chiujang@hotmail.com>
Date:   Tue May 7 08:37:31 2024 +0800

    init repo commit
```
# 發行到 github 
### 先自行新建好 GitHub 的 Repository，
開啟終端機，在該目錄下輸入以下指令
```
# 這行指令只需要輸入第一次即可
git remote add origin https://github.com/richardchiujang/hch_ocr

# 分支
git branch -M main

git push -u origin main
```
結果如下:
```
git push -u origin main
info: please complete authentication in your browser...
Enumerating objects: 89, done.
Counting objects: 100% (89/89), done.
Delta compression using up to 32 threads
Compressing objects: 100% (88/88), done.
Writing objects: 100% (89/89), 108.10 KiB | 13.51 MiB/s, done.
Total 89 (delta 14), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (14/14), done.
To https://github.com/richardchiujang/hch_ocr
 * [new branch]      main -> main
branch 'main' set up to track 'origin/main'.
```
### 有新增檔案 或是 修改檔案時，只需要執行以下幾個步驟即可
```
git add .
git commit -m "message"
git push -u origin main
```
範例如下:
```
(hch_ocr) c:\develop\hch_ocr>git add README.md

(hch_ocr) c:\develop\hch_ocr>git status
On branch main
Your branch is up to date with 'origin/main'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   README.md

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   .gitignore

(hch_ocr) c:\develop\hch_ocr>git commit -m "v0.4 2024/04/24 補說明更新內容在READ.me"
[main 6ed98ba] v0.4 2024/04/24 補說明更新內容在READ.me
 1 file changed, 7 insertions(+)
 
(hch_ocr) c:\develop\hch_ocr>git push -u origin main
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 32 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 583 bytes | 583.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To https://github.com/richardchiujang/hch_ocr
   4867f95..6ed98ba  main -> main
branch 'main' set up to track 'origin/main'. 
```
### github 內容
![image](https://hackmd.io/_uploads/B1p1lfDzR.png)
記得github內容盡量不要在網頁中修改(更新)不然會造成後續local push衝突
或者要先做 git pull (github)拉新版下來同步(local 修改前)
或 rebase 等動作

### git log
```
(hch_ocr) c:\develop\hch_ocr>git log
commit 92259113a9396c2ea802c2d4a3b417951c3b34a5 (HEAD -> main, origin/main)
Author: Richard Chiu <34330633+richardchiujang@users.noreply.github.com>
Date:   Tue May 7 10:17:40 2024 +0800

    Delete license

commit 710deaa2bf8ab4a5679cf41c3268c4fdab737f0d
Author: Richard Chiu <chiujang@hotmail.com>
Date:   Tue May 7 10:14:41 2024 +0800

    add LICENSE.md Apache License Version 2.0, January 2004

commit 0027f4ebc986586e1314d0e8e55cef3ce5ba643b
Author: Richard Chiu <chiujang@hotmail.com>
Date:   Tue May 7 10:09:46 2024 +0800

    remove license file (add to .gitignore)

commit 6ed98bab92346b0ede991263e9c313c2022042e7
Author: Richard Chiu <chiujang@hotmail.com>
Date:   Tue May 7 10:04:48 2024 +0800

    v0.4 2024/04/24 補說明更新內容在READ.me

commit 4867f955e8678751cf754c657ba4058380fe5a7b
Author: Richard Chiu <chiujang@hotmail.com>
Date:   Tue May 7 08:37:31 2024 +0800

    init repo commit
```
按鍵q離開

