Git
- Git 的故事:這一次沒這麼好玩 | 軟體考古學家
- A Visual Git Reference
- Modern Git Commands and Features You Should Be Using | Martin Heinz | Personal Website & Blog
- How to Store Dotfiles - A Bare Git Repository | Atlassian Git Tutorial
- Git 小技巧 - 切換為特定 Github 帳號維護專案-黑暗執行緒
- 新 Git 指令之你該試試看了 | 是 Ray 不是 Array
- Git: How to enable autocorrect - Adam Johnson
- :star:Git 軟體開發指南:提高團隊協作的關鍵 - 小惡魔 - AppleBOY
- 初探輕量級 DevOps 平台: Gitea - 台北 DevOpsDay - 小惡魔 - AppleBOY
- 主幹開發簡介 - trunk based development
~/.bashrc
# git branch in bash prompt
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
export PS1="\u@\h \[\e[32m\]\w \[\e[91m\]\$(parse_git_branch)\[\e[00m\]$ "
config
- How to show or change your Git username or email address | alvinalexander.com
- [Git] 檔案權限改變,導致所有的檔案都被 Git 視為已修改? | EPH 的程式日記
# 查看設定
$ git config --list
# 檢查username
$ git config user.name
# 設置user name
$ git config --global user.name "Ted.Changchien"
# 設置email
$ git config --global user.email "Ted.Changchien@zyxel.com.tw"
# 設置commit log template
$ git config --global commit.template /path/to/log-template-file
# 設置commit編輯器
$ git config --global core.editor "vim"
# git log show ^M
$ git config --global core.whitespace cr-at-eol
# alias
$ git config --global alias.tree "log --graph --decorate --pretty=oneline --abbrev-commit"
# filemode
$ git config core.filemode false
unset
git config --global --unset user.name
git config --global --unset user.email
# edit directly
git config --global --edit
remote
- Working with Git remotes and pushing to multiple Git repositories
- Delete remote branch
- git Local 端與 Remote 端的分支操作. 前言 | by Kiwi lee | Medium
# 設置遠端倉庫的URL
$ git remote set-url origin https://github.com/USERNAME/OTHERREPOSITORY.git
$ git remote set-url origin git@192.168.188.95:UploadPlatform.git
# 更改遠端主機資訊
$ git remote -v
$ git remote rm origin
$ git remote add origin git@git-server:project_name
# 連結 remote repository 的 branch 到新建的 local branch
$ git branch --set-upstream-to=origin/feature3 feature3
# 刪除遠端分支
$ git push origin :feature_a
# clean up the reference to the deleted remote branch from your local repository
$ git fetch origin --prune
stash
暫存working directory 想要拉回遠端repo的新commit但想暫時保存目前還沒有做local commit且正在修改的部分
tags
git tag -a v1.2.1b3
git push origin v1.2.1b3
# 對過去的commit上加入標籤
git tag -a v1.3.0b2s2 9fceb02
# Delete the tag from the repository
git tag -d <tag name>
git fetch --tags
git push origin --tags
log
# search log by commit message
git log --grep='JIRA ID'
# log filter by author
git log --author="Jon"
# 顯示檔案資訊
git log --name-status
# find commit by hash sha in git
git show a2c25061
git log a2c25061 -n 1
git show a2c25061 --stat
# view the change history of a method/function
git log -L :function:path/to/file
# find a deleted file in the project commit history
# do not know the exact path
git log --all --full-history -- "**/thefile.*"
# know the path the file was at
git log --all --full-history -- <path-to-file>
patch
# 製作最近n個commit的patch
git format-patch -n
# 製作從指定起始commit到結束commit的patch
git format-patch 5e86795..f2b286a
# 設定輸出的資料夾
git format-patch 5e86795..f2b286a -o {Dir Name}
# 檢查套用patch是否會有問題
git apply --check {patch_file}
# 實際套用patch
git am {patch_file}
notes: 有[]會消失
push
pull
add
Commit only part of a file in Git
例如: refactory時改import, 但其他部分和refactory無關 https://stackoverflow.com/questions/1085162/commit-only-part-of-a-file-in-git
git add -p <filename>
Stage this hunk [y,n,q,a,d,/,j,J,g,s,e,?]?
Here is a description of each option:
y stage this hunk for the next commit
n do not stage this hunk for the next commit
q quit; do not stage this hunk or any of the remaining hunks
a stage this hunk and all later hunks in the file
d do not stage this hunk or any of the later hunks in the file
g select a hunk to go to
/ search for a hunk matching the given regex
j leave this hunk undecided, see next undecided hunk
J leave this hunk undecided, see next hunk
k leave this hunk undecided, see previous undecided hunk
K leave this hunk undecided, see previous hunk
s split the current hunk into smaller hunks
e manually edit the current hunk
? print hunk help
bundle
Commit
- Conventional Commits
- 自動產生 semantic Versioning 版號與資訊, 使用 semantic-release 或 standard-version
- generating-changelog-standard-version
real world example
diff
what changes between two commits and only the filename Git: How to show only filenames for a diff - makandra dev
Flow
持續發布 版本發布
參考
- 三種版控流程
- 與其它開發者的互動 - 使用 Pull Request(PR)
- Chaser324/GitHub-Forking
- How can I tell a local branch to track a remote branch
Rebase
- Git-rebase 小筆記 - Yu-Cheng Chuang’s Blog
- Git 版本控制教學 - 用範例學 rebase - MyApollo
- 送 PR 前,使用 Git rebase 來整理你的 commit 吧!
- 使用 git rebase --onto 無痛更新分支 | Summer。桑莫。夏天
Conflict
Revert
某個 Commit 反向的操作 - eset、Revert 跟 Rebase 指令有什麼差別
Discard change
cherry pick
# To cherry-pick all the commits from commit A to commit B (where A is older than B)
git cherry-pick A^..B
# If you want to ignore A
git cherry-pick A..B
sparse checkout
bisect
submodule
- Git 版本控制教學 - submodule - MyApollo
- Git - submodule 使用教學 | Kenny's Blog
- Git 進階應用 Submodule 與 Subtree,使用它們來拆分專案 | Puck's Blog
- 更新 Submodule
- git - How do I remove a submodule? - Stack Overflow
- [Git] 更新 Git submodule 時出現 not our ref 的錯誤訊息? | EPH 的程式日記
- How can I authenticate my information with a submo...
fix corrupt submodule - git submodules - could not get a repository handle for submodule - Stack Overflow
rm -rf .git/modules/the_submodule/ the_submodule/
git submodule init "the_submodule"
git submodule update
LFS
protect secret leak
- Gitleaks — 幫你偵測/防止金鑰、密碼被不小心 commit 的情況 - MyApollo
- GitHub - newren/git-filter-repo: Quickly rewrite git repository history (filter-branch replacement)
工作原理
- Git内部存储原理-赵化冰的博客 | Zhaohuabing Blog
- In a git repository, where do your files live?
- Write yourself a Git!
hook
post-commit