CSST 程式設計討論會 2023
Author: Sean 韋詠祥
Note:
日期:2023-05-10(三)
時間:19:00 - 21:00
TODO:
webserver .git/config
merge conflict
git reflog
reflog game
git commit
git tag
gui
git blame
先開啟 iTerm2 或 Terminal 終端機
輸入 git 指令,內建的 Xcode 將會跳出安裝資訊
git --version
搜尋 Git for Windows
基本上都下一步,編輯器這邊可以改成自己慣用的
相信你知道怎麼做的 :D
# Debian / Ubuntu
apt install git
# Fedora
dnf install git
# Arch Linux
pacman -S git
# Alpine
apk add git
先大概理解就好,也可以上網查「Bash XXX 用法」
Note:
2022/11/02
上學期教過初探 Linux
ls # 列出目前目錄下的檔案
ls -a # 包含隱藏檔案
ls -l # 顯示詳細資訊
ls -al # 我全都要!
pwd # 顯示當前目錄名稱
cd Documents # 進入資料夾
cd .. # 回到前一層目錄
cd # 不加參數,代表回到家目錄
Note:
知道在哪、探索、移動
mkdir mycode # 建立資料夾
touch myfile # 產生空檔案
mv myfile file1 # 移動檔案
cp file1 file2 # 複製檔案
echo Hey
echo "Hello World" > file3
cat /etc/passwd # 印出檔案內容
less /etc/passwd # 慢慢查看檔案內容
rm file1 # 刪除檔案
rmdir mycode # 刪除空資料夾
Note:
對 Git 來說,支援分岔
git config --global user.name "Sean" # 你的暱稱
git config --global user.email me@sean.taipei
git config --global alias.lg "log --color --graph --all --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --"
git config --global gc.auto 0 # Disable garbage collection
git config --global pull.ff only # Fast-forward only
git config --global core.excludesFile = ~/.gitignore
git config --global rerere.enable true # Reuse Recorded Resolution
git config --global rebase.autosquash true
git config --global checkout.defaultRemote origin
Note:
Removed
git config --global core.editor 'vim'
git config --global merge.tool vimdiff
git config --global init.defaultBranch master
git config --global url."git@github.com:".insteadOf "https://github.com/"
Git Repository
cd ~/Documents
mkdir my-project # 建立資料夾
cd my-project
git init # 初始化 git
touch main.py # 建立 main.py 或 main.cpp 檔案
git add main.py # 把檔案從 working area 加入 staging area
git commit
# 在編輯器中輸入 commit 訊息:init
# 完成!
先用編輯器打開 main.py
檔案
explorer . # Windows: 用檔案總管開啟資料夾
open . # macOS: 開啟資料夾
EDIT main.py # Linux: 直接編輯檔案
用 for
跟 range()
讓他輸出 0 到 4 這五個數字,每次換行
完成後用 git 保存版本紀錄
git status # 有誰被改到了
git add main.py
git commit
Note:
先講 status
下頁講 diff
再來是 show
輸入:一個正整數 N
輸出:從 0 到 N-1 的數字,每次換行
git diff # 我們改了什麼
git add -p main.py
git commit
Hint:用 int(input())
接收輸入
Note:
剛講 status
現在是 diff
下頁講 show
輸入:一個正整數 N
輸出:從 1 到 N 的數字,每次換行
git add -p .
git commit -m '<commit message>'
試著查看歷史紀錄
git show # 預設為 HEAD
git show HEAD~1 # 往前 1 筆
Note:
講完 status、diff
這頁講 show
別把我的黑歷史記下來 (/ω\)
當我們有個不必要的檔案
echo __pycache__/ >> .gitignore
echo config.py >> .gitignore
cat .gitignore
git add .gitignore
假如我們要從 git 歷史中
完整刪除 pkg/
底下所有 .deb
檔案
git filter-branch --force --index-filter \
'git rm --cached --ignore-unmatch pkg/*.deb' \
--prune-empty --tag-name-filter cat
參閱:凍仁的筆記(2014)
git remote add origin https://github.com/<User>/<Repo>.git
git remote -v
git push -u origin master
touch README.md # 去編輯 README.md 檔案
git add README.md
git commit
git push
git fetch --all
git pull
git log
讓我們進到 Git 進階用法
小練習:
輸入前詢問「Input N: 」
輸出 0 到 N-1
git switch -h # --help
git switch -c feat-prompt-input # --create
git push
git push -f # --force
git push --force-with-lease
git restore
git clean -x -i -d # no-ignore, interactive, directory
git stash
git stash pop
git rebase -i master
救回被 rebase 到不見的檔案
git reflog
Demo: Sea-n/my-python-project
Note:
找 secret
測試 rebase 後 reflog
提醒 working area / staging / git
Learn Git Branching Challenge
網址:https://learngitbranching.js.org/
投影片連結:https://hackmd.io/@Sean64/git-csst2023
or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing