Git 入門
Git / Git Server / Git flow
什麼是版本控制?
教授要刻一顆 CPU,有 Cache 功能加十分
於是,有了漫長的旅程…
環境設定
| git config --global user.email "you@example.com" |
| |
| git config --global user.name "Your Name" |
| |
| git config --global color.ui true |
| |
| git config --global core.editor vim |
| |
| git config --global alias.co commit |
| |
| 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 --" |
- man git
- git help <command>
- stackflow
原理
git 會儲存每次的修改
藉由 hash 維護修改紀錄
hash value 會往上疊加 (前一個 hash + 修改)
新改變後…
- git status
- git diff
- git add
- git commit (-m)
- git log
何時 commit?
如何 commit?
commit –amend
Branch
- git branch
- git checkout -b

Checkout
- git checkout {branch name}
- git checkout {commit hash}
Merge
- git merge (–no-ff)
- git rebase
- git cherry-pick

Other trick
- git stash (save / list / pop)
- git blame
- git tag
- git format-patch -2 -o ./output
- git am ./output
本地端版控

集中式

分散式

以 GitHub 為例
申請 GitHub 帳號
新增 repo
Git Clone
- git clone (downstream / upstream)
- git remote add origin https://…
- git remote set-url origin git@://…
- git remote (add / show / -v)
- git fetch
- git pull (fetch + merge)
- git push (-u)
SSH vs HTTPS
- git clone https://…
- git clone git@…
- ssh key (~/.ssh/id_rsa.pub)
找戰犯囉~
- git log ( –author / –since= / –until= / regex)
- git show
- git blame
尋找錯誤
- git diff
- git difftool
- git checkout
暫存
- git stash
git stash save "msg"
git stash list / show / apply / drop / pop
- 參考
工作目錄
- 創造出另一個工作目錄 (通常建再版控以外的地方)
git worktree add -b branch /path/to/new/dir
- 參考
復原
- git reset (--hard)
- git revert
- 參考差別
- 只 reset 某一個檔案
- git checkout HEAD(commit) -- {file_name}
刪除 untrack
git clean (-f -d)
Others
- fork
- submodule
- issue
- pull request / merge request
- CI (Continuous Integration)
- downstream / upstream
Git Flow

GitHub Flow

GitLab Flow

git clone --recursive git@bitbucket.org:free5gc-team/free5gc.git
- Open task
- Create feature branch on submodule (NF/lib)
- work & commit on submodule
- Merge feature branch back to develop branch (using PR)
- Create branch on
free5gc
(main repo)
- Add develop commit of your feature
- Merge branch to develop (using PR)
Git 入門 Git / Git Server / Git flow
{"metaMigratedAt":"2023-06-14T13:03:28.870Z","metaMigratedFrom":"YAML","title":"Git 入門","breaks":true,"description":"WDC Git 入門","lang":"zh-tw","dir":"ltr","robots":"index, follow","GA":"UA-100433652-1","disqus":"calee","contributors":"[{\"id\":\"7e8541c8-f55f-499e-991d-1bfe90b9cbb8\",\"add\":1382,\"del\":34}]"}