skillful at git
- 工作区:(增删文件和内容)
- 暂存区:
git add 改动的文件名此次改动就放到了暂存区 - 本地仓库(本地):
git commit 此次改动的描述此次改动就放到了本地仓库,每一个 commit 就是一个版本 - 远程仓库(远程):
git push 远程仓库此次改动就放到了远程仓库 - commit-id:
git log输出提交的信息
git help -g
git help -a
git reset --hard origin/master
也就是把所有的改动重新放回工作区,并清空所有的 commit 这样就可以重新开始第一个 commit 了
git update-ref -d HEAD
git push -f <remote-name> <remote-branch>
输出工作区和暂存区的不同(哪些 add 了,哪些没有 add)
git diff
展示本地仓库中任意两个 commit 中的文件变动
git diff <commit-id> <commit-id></commit-id>
git diff HEAD
git checkout -
git branch --merged master | grep -v '^\*\| master' | xargs -n 1 git branch -d
git branch -vv
关联之后,git branch -vv 就可以展示关联的远程分支名了,同时推送到远程仓库直接:git push,不需要指定远程仓库了。
git push -u origin master
git branch -r
git branch -a
git remote show origin
git remote prune origin
git checkout -b <branch-name> origin/<branch-name>
git branch -d <branch-name>
git push origin --delete <branch-name>
git branch -m <new-branch-name>
git tag <version-number>
默认 tag 是打在最近一次 commit 记录上,如果需要指定 commit 打 tag
git tag -a <version-number> -m '描述' <commit-id>
git push origin <local-version-number>
一次性推送所有
git push origin --tags
git tag -d <tag-name>
需要先删除本地标签,再删除远程标签
git push orgin :refs/tags/<tag-name>
git checkout -b <branch-name> <tag-name>
git tag
展示当前分支最近的 tag
git describe --tags --abbrev=0
查看标签的详细信息
git tag -ln
git checkout <file-name>
放弃所有更改
git checkout .
git revert <commit-id></commit-id>
git reset <commit-id> #默认就是-mixed参数。
git reset --mixed HEAD^ #回退至上个版本,它将重置HEAD到另外一个commit,并且重置暂存区以便和HEAD相匹配,但是也到此为止。工作区不会被更改。
git reset --soft HEAD~3 #回退至三个版本之前,只回退了commit的信息,暂存区和工作区与回退之前保持一致。如果还要提交,直接commit即可
git reset --hard <commit-id> #彻底回退到指定commit-id的状态,暂存区和工作区也会变为指定commit-id版本的内容
git commit --amend
git blame <file-name>
每次更新了 HEAD 的 git 命令比如 commit、amend、cherry-pick、reset、revert 等都会被记录下来(不限分支),就像 shell 的 history 一样,这样你就可以 reset 到任何一次更新了 HEAD 的操作之后,而不仅仅是回到当前分支下的某个 commit 之后的状态
git reflog
git commit --amend --author="GerritV<[email protected]>"
git remote set-url origin <URL>
git remote add origin <remote-url>
git remote
git whatchanged --since="2 weeks ago"
git checkout <branch-name> && git cherry-pick <commit-id>
git stash
git stash -u
git stash list
git stash apply <stahs@{version}> // 这个 list 是栈
git stash pop(感觉不太好用)
git stash clear
git log --pretty=oneline --graph --decorate --all
和我自己配的 glog 差不多
git bundle create <file> <branch-name> // 二进制文件
git rebase --autostash
git fetch origin pull/<id>/head:<branch-name>
git diff --word-diff
git clean -X -f
git status --ignored
git config --local --list(当前目录)
git config --global --list(全局)
igt log <Branch1> <^Branch2>
git log --show-signature
git config --global --unset <entry-name>
git clone --orphan <branch-name>
git show <branch-name>:<file-name>
git clone -b <branch-name> --single-branch xxx.git
只会 clone 最近一次提交,将减少 clone 的时间
git clone --depth=1 xxx.git
关闭 track 指定文件的改动,也就是 Git 将不会在记录这个文件的改动
git update-index --assume-unchanged path/to/file
恢复 track 指定文件的改动
git update-index --no-assume-unchanged path/to/file
不再将文件的权限变化视作改动
git config core.fileMode false
git for-each-ref --sort=-committerdate --format='%(refname:short)' refs/heads/
git log --all --grep='<given-text>'
不加参数 默认是 -mixed
git reset <file-name>
git push -f <remote-name> <branch-name>
git config --global https.proxy 'http://127.0.0.1:8001' # 适用于 privoxy 将 socks 协议转为 http 协议的 http 端口
git config --global http.proxy 'http://127.0.0.1:8001'
git config --global socks.proxy "127.0.0.1:1080"
$ cat ~/.ssh/config
Host gitlab.com
ProxyCommand nc -X 5 -x 127.0.0.1:1080 %h %p # 直接使用 shadowsocks 提供的 socks5 代理端口
Host github.com
ProxyCommand nc -X 5 -x 127.0.0.1:1080 %h %p
