今天看到朋友講了一個 git 指令,想說順便分享一下我自己常用的指令,算是野人獻曝。
config#
首先是 ~/.gitconfig,放一些 global 的 git 環境變數,可以在裡面設定自己常用的名稱,以及 alias
[color]
ui = auto
[user]
name = YOUR_COMMIT_AUTHOR_NAME
email = someone@foo.bar
[alias]
lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
ld = log --decorate --graph
lf = log --pretty=fuller --decorate --graph
s = status
amd = commit -a --amend
cm = commit --amend
co = commit
ca = commit -a
ck = checkout
ri = rebase -i
ri5 = rebase -i HEAD~5
ri10 = rebase -i HEAD~10
ra = rebase --abort
rc = rebase --continue
cp = cherry-pick
rb = rebase
[diff]
algorithm = patience
[core]
editor = vim
autocrlf = input
quotepath = false
[push]
default = simple
[url "git@github.com:"]
insteadOf = https://github.com/
[tig "bind"]
# use 'Z' to see commit via vimdiff
generic=Z !sh -c 'git difftool %(commit)^ %(commit)'從這些 command 就可以輕易看出我最常做的事,不外乎就是對 commit 修修剪剪,git rebase -i 真是宅宅的好朋友。
- 在專案裡面新增
.gitignore可以叫 git 忽略、不去管理部份檔案,通常用在編譯出來的檔案 - 如果是一些自己手動的東西需要忽略,不適合放進 .gitignore 給專案的其他人知道,可以寫進
.git/info/exclude
patch#
只有某幾個修改要給別人的時候,可以用 diff 或是 format-patch 來產生 patch,然後用 apply / am 來打上 patch
format-patch 與 am 是成對的,可以透過 e-mail 來更方便傳遞,但我沒試過。喜歡用 format-patch/am 是因為這樣的 patch 看起來資訊含量比較多。
| |
手動新增 object#
以前還要用 repo sync 奮鬥的時候,常常因為網路或是其他問題,搞到自己的 repository 裡面少了幾個 git object,那時候 kanru 教過這招可以把檔案塞進去
| |
其他指令#
一些偶爾會用到,但是很容易忘記的指令。其實原本是持續更新在我自己的 local wiki 筆記裡面,直接複製貼上到這邊。
| |