2019/08/01 (Edit 2019/08/27)
git, tip, command-lineSome tip for hacking Git.
git fetch
, ditch git pull
rebase
, ditch merge
(except for pull-request)cherry-pick
, learn interactive rebase
.git/config
, limit your global git config
Here's some tip for hacking Git: a powerful tool to manage text across some time within a team
The commit
.git/objects/
, and the relation to commit?The branch
The rebase
The conflict
git fetch
, ditch git pull
git pull
is a failed combo command,
usually it'll cost you current un-committed change,
and result in a hard reset.
so to skip the hassle, just git fetch
to get the future
,
then git reset --hard @{upstream}
when you're clear to get the change
rebase
, ditch merge
(except for pull-request)consider this when working with long branches (16+ commit).
merge cause messy history, and not able to do rebase is also a sign of bad git commit habit
focus the change, sort the commit, and use rebase
cherry-pick
, learn interactive rebase
if you do cherry-pick
enough times, you got rebase
if you change commit content during multiple cherry-pick
, you got interactive rebase
moving commit can clean up the repo history
reordering & regrouping commits gives high quality history
if there's some later use for the commit history, and the quality of commit message matters, do both regularly
ADD: feat-B
ADD: feat-A
UPD: feat-A
UPD: feat-B
CHG: feat-B
CHG: feat-A
FIX: feat-B
FIX: feat-A
later you may sort the commit to like: (or squash the fix)ADD: feat-A
UPD: feat-A
CHG: feat-A
FIX: feat-A
ADD: feat-B
UPD: feat-B
CHG: feat-B
FIX: feat-B
.git/config
, limit your global git config
[core]
sshCommand = ssh -i ~/.ssh/key-for-repo-a.pri
\n
,
edit the config like:[core]
ignorecase = false
symlinks = false
autocrlf = input
eol = lf
[remote "origin"]
url = git@github.com:user/repo.git
fetch = +refs/heads/master:refs/remotes/origin/master
fetch = +refs/heads/test:refs/remotes/origin/test
fetch = +refs/heads/feat-a/*:refs/remotes/origin/feat-a/*
fetch = +refs/heads/feat-b/*:refs/remotes/origin/feat-b/*
# fetch = +refs/heads/*:refs/remotes/origin/* # do not fetch all