Git 命令备忘

配置代理

# set proxy
$ git config --global http.proxy http://<账号>:<密码>@<主机>:<端口>
$ git config --global https.proxy https://<账号>:<密码>@<主机>:<端口>

# check proxy
$ git config --global --get http.proxy 
$ git config --global --get https.proxy

# unset proxy
$ git config --global --unset http.proxy
$ git config --global --unset https.proxy

Alias

$ git config --global alias.hist "log --color --graph --pretty=format:'%Cred%h%Creset - %Cgreen(%ci)%Creset %s %C(bold blue)<%an>%Creset%C(yellow)%d%Creset' --abbrev-commit"
$ git config --global alias.recover '!git clean -df && git reset HEAD --hard'
$ git config --global alias.updbr '!git checkout master && git branch -D feature/code_association_rule_mining && git pull --ff-only && git checkout feature/code_association_rule_mining'

Log

$ git log --author='author_name' --before='yyyy-mm-dd hh:mm:ss' --after='yyyy-mm-dd hh:mm:ss' --first-parent
$ git log --follow -- 'filepath'

Diff

$ git diff 'from'..'to' -- 'filepath'

Tag

$ git tag 'light-weight tag name' 'commit-ish'
$ git tag -a 'anotated tag name' -m 'tag message'

rename branch locally and remotely

$ git branch -m ['old_br_name'] 'new_name'
$ git push 'repo' -d 'old_br_name'
$ git push 'repo' -u 'new_name'

Rebase

$ git rebase --onto 'target_commit-ish' 'start_commit-ish(exclude)' 'end_commit-ish(include)'
$ git rebase --quit

Others

$ git remote add origin 'url'

# to see commit that certain-branch doesn't have but current branch does have
$ git cherry -v 'certain-branch' 

# to see all commit id of merges that merges into current branch
$ git log --pretty=format:%H --merges --first-parent
# to see changing statistics of certain commit
$ git show 'commit-id' --pretty=format:%aI --numstat

$ git log -p --merges --first-parent

# extract commits to patch file
$ git format-patch -4 HEAD 
# apply commits
$ git am *.patch

$ git diff --merge-base bsp/develop master -- '**/*.c'

# roll back file to a commit-ish
git checkout 'COMMIT_HASH' -- 'FILE_PATH'

# list all changed files from commit-ish to HEAD
git diff --name-only 'COMMIT_HASH' HEAD

# permit root user perform actions in a repo that is owned by another user
git config --system --add safe.directory /path/to/dir
posted @ 2023-10-07 16:53  LexLuc  阅读(9)  评论(0编辑  收藏  举报