git
Last updated
source /dev/stdin <<< "$(curl -sSL https://raw.githubusercontent.com/fzinfz/scripts/master/lib/git.sh)"cat .git/HEAD # current branch head
ref: refs/heads/master
cat .git/ORIG_HEAD ; git show | head -1git commit -am "save arezzo files"
git commit --amend
-c, --reedit-message <commit> # reuse and edit message from specified commit
-C, --reuse-message <commit> # reuse message from specified commitgit log [<options>] [<revision-range>] [[--] <path>...]
git show [<options>] <object>...
git show [path] # details of last commit log
git log --since=2.weeksgit branch -a # list all
git checkout -b dev # create and checkout a new branch
git checkout master
git merge dev # merge dev into master
--squash create a single commit instead of doing a merge
--abort abort the current in-progress mergegit checkout -- <file> # discard changes in working directory
git reset HEAD~2 # undo 2 changes that haven’t been shared
git reset <paths> # opposite of `git add <paths>`
--soft reset HEAD only
--mixed reset HEAD and index (default)
--hard reset HEAD, index and working tree
--merge reset HEAD, index and working tree
--keep reset HEAD but keep local changes
git revert HEAD~2 # undo 2 changes on a public branchgit reset master
git checkout mastergit stash
git stash list
git stash apply/pop
git stash apply stash@{2}
git stash drop
git stash drop stash@{0}git remote -v
git remote add [<options>] <name> <url>
-f, --fetch fetch the remote branches
--tags
--no-tags
-t, --track <branch> # branch(es) to track
-m, --master <branch>
--mirror[=<push|fetch>] # set up remote as a mirro
cat .git/config
`refspec`: +<src>:<dst>
<src> is the pattern for references on the remote side
<dst> is where those references will be tracked locally
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
fetch = +refs/heads/master:refs/remotes/origin/master
fetch = +refs/heads/foo/*:refs/remotes/origin/foo/*
git push -u origin master:refs/heads/foo/master
push = refs/heads/master:refs/heads/qa/master
tree .git/refs/
.git/refs/
├── heads
│ ├── dev
│ └── master
├── remotes
│ └── origin
│ └── HEAD
└── tags
git push [<options>] [<repository> [<refspec>...]]
-u, --set-upstream set upstream for git pull/status
git pull origin master # fetch + mergegit push origin :topic
git push origin --delete topicgit config -l
--global ~/.gitconfig
--local .git/config
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
--system /etc/gitconfig
--get get value: name [value-regex]
--get-all get all values: key [value-regex]
--get-regexp get values for regexp: name-regex [value-regex]
--get-urlmatch get value specific for the URL: section[.var] URL
--replace-all replace all matching variables: name value [value_regex]
--add add a new variable: name value
--unset remove a variable: name [value-regex]
--unset-all remove all matches: name [value-regex]
git config --global push.default simple
git config --list --show-origingit config --global http.proxy http://$IP:$Port[--setup <command>]
[--env-filter <command>]
[--tree-filter <command>]
[--index-filter <command>]
[--parent-filter <command>]
[--msg-filter <command>]
[--commit-filter <command>]
[--tag-name-filter <command>]
[--subdirectory-filter <directory>]
[--original <namespace>]
[-d <directory>] [-f | --force] [--] [<rev-list options>...]git rm --cached giant_file # leave it on disk
git commit --amend -CHEADgit filter-branch --tree-filter 'rm -f filename' HEAD
--all # all branches
git filter-branch --index-filter \
'git rm --cached --ignore-unmatch filename' HEADgit remote add upstream https://github.com/yeasy/docker_practice
git fetch upstream
git checkout master
git rebase upstream/master
git push -f origin mastercurl -sSL https://api.github.com/repos/django/django/tags \
| jq '.[0].zipball_url' | xargs -t wget -O file.zipcurl -H 'Authorization: token INSERT_ACCESS_TOKEN_HERE' \
-H 'Accept: application/vnd.github.v3.raw' -O -L \
https://api.github.com/repos/owner/repo/contents/pathcurl -sSL https://api.github.com/repos/ParsePlatform/Parse-SDK-Android/releases/latest \
| jq '.zipball_url' | xargs -t wget -O file.zip