Git 教學 (Git Tutorial)
git 教學與筆記。
Basic settings
1 | git --version |
Init
1 | git init |
ssh-key
1 | cd ~/.ssh |
Clone
1 | git clone -b "<specific branch>" --single-branch "<git repository url>" "<local folder name>" |
Add
1 | git add "<file>" |
Status
1 | git status . |
Commit
1 | git commit -m "<commit name>" |
Patch
1 | git format-patch -1 <commit> -o ~/test_code/patch # 從包含 <commit> 往前算共 1 個 commit |
Cherry-pick
1 | git cherry-pick "<commit ID>".."<commit ID>" # (注意第一個編號要是前一個commit) |
Log
1 | git log |
Show
1 | git show "<commit>" --stat |
Diff
1 | git diff "<commit>" "<commit>" |
grep
1 | git ls-files | fgrep "test.c" |
Checkout
1 | git checkout "<file>" |
Reset
1 | git reset HEAD --hard |
Clean
1 | git clean -f -d |
Branch
1 | git branch -a |
Merge
1 | git merge "<branch name>" |
Remote
1 | git remote -v |
Push
1 | git push "<remote>" "<commit SHA>":"<remote branch>" |
Fetch
1 | git fetch origin |
Pull
1 | git pull |
Rebase
1 | git rebase -i "<commit>" |
Tag
1 | git tag |
Stash 封存
1 | git add . |
Gerrit
1 | git review -R |
Share the code
Upgrade to latest git version
1 | (option) sudo rm -rf /usr/share/ca-certificates |
Fix denyCurrentBranch issue
Error message :
1
2remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repositorySolution : Add below setting in
~/.gitconfig
1
2[receive]
denyCurrentBranch = ignore
Git 教學 (Git Tutorial)