Git
-- Repo*
|-- .git*
| |-- hooks*
| |-- info*
| |-- logs*
| |-- objects*
| |-- refs*
| |-- COMMIT_EDITMSG
| |-- config
| |-- description
| |-- HEAD
| |-- index
|-- .gitignore
*: Folders
HEAD§
HEAD^
: previous commit
HEAD~<n>
: last n commits
working area§
Git commands | options | description |
---|---|---|
clone | Clone a repository into a new directory | |
init | Create an empty Git repository or reinitialize an existing one |
current change§
Git commands | options | description |
---|---|---|
add | Add file contents to the index | |
mv | Create an empty Git repository or reinitialize an existing one | |
restore | Restore working tree files | |
rm | Remove files from the working tree and from the index |
history and state§
Git commands | options | description |
---|---|---|
diff | Show changes between commits, commit and working tree | |
log | Show commit logs | |
--grep |
搜索关键字 | |
show | Show various types of objects | |
status | Show the working tree status |
commit§
Git commands | options | description |
---|---|---|
commit | Record changes to the repository | |
-a, --all |
commit all changed files | |
-m, --message <message> |
commit message | |
--amend |
amend previous commit | |
reset | [<commit>] |
Reset current HEAD to the specified state |
--hard |
reset HEAD, index and working tree | |
--soft |
reset only HEAD | |
tag | <tagname> [<head>] |
Create, list, delete or verify a tag object signed with GPG |
collaborate§
Git commands | options | description |
---|---|---|
fetch | [<repository>] |
Download objects and refs from another repository |
pull | Fetch from and integrate with another repository or a local branch | |
push | Update remote refs along with associated objects |
branch§
Git commands | options | description |
---|---|---|
branch | List, create, or delete branches | |
checkout/gco | <branch> |
|
-b <branch> |
create and checkout a new branch | |
merge | Join two or more development histories together | |
rebase | [<upstream> [<branch>]] |
Reapply commits on top of another base tip |
-i, --interactive |
let the user edit the list of commits to rebase |
remote§
Git commands | options |
---|---|
remote | [-v |--verbose] |
add <name> <url> |
|
rename <old> <new> |
|
remove <name> |
config§
Git commands | options | description |
---|---|---|
config | ||
--global |
use global config file | |
--local |
use repository config file | |
-l, --list |
list all | |
-e, --edit |
open an editor |
常用配置项
section | key |
---|---|
user | name, email |
http | sslverify |
https | sslverify |
core | bare |
credential | helper |
submodule§
Inspects, updates and manages submodules.
The first one works for git version
1.8.2
or above while the second one works for git version1.7.3
or above.
clone§
git clone --recursive https://github.com/taichi-dev/taichi
init§
git submodule update --init --recursive --depth=1
update§
git submodule update --recursive --remote
git submodule update --recursive
git pull --recurse-submodules
bare repository§
普通仓库用来干活(working),bare 仓库用来共享(sharing)。
Git 提供了分布式版本管理的方案,多人协作仍然需要一个中心式仓库用来同步工作。比如 GitHub 上的仓库就是 bare 仓库。
Bare 仓库中没有 working tree,因此不能在 bare 仓库中进行修改和提交。对 Bare 仓库只能 push
或 clone
。
git init --bare
git config --bool core.bare true
# 类似 push,将变更 clone 到 bare-repo
git clone –bare <bare-repo>
# 如果想要 push 到一个普通仓库,这个仓库需要设置,以接受工作树的不一致
# push 后仓库只会改变 HEAD 指针,需要 git reset --hard 同步索引和工作树
git config receive.denyCurrentBranch ignore
Bare 仓库类似与普通仓库中的.git
目录。
Bare 仓库通常使用.git
作为目录名的后缀。
-- BareRepo.git*
|-- hooks*
|-- info*
|-- logs*
|-- objects*
|-- refs*
|-- COMMIT_EDITMSG
|-- config
|-- description
|-- HEAD
|-- index
*: Folders
speedup§
Mirror sites§
在码云上查看项目是否存在镜像,也可以在码云中导入 GitHub 账号 fork 的仓库。
替换 clone 时的仓库地址。
WSL§
V2ray
- 允许局域网连接。
- 允许通过 Windows 防火墙。
proxychains§
sudo apt install proxychains
安装后编辑 /etc/proxychains.conf 文件,修改最后一行。
[ProxyList]
# add proxy here ...
# meanwile
# defaults set to "tor"
socks5 127.0.0.1 10808
在命令前添加 proxychains,如 proxychains git clone ...
。
ALL_PROXY§
在 .zshrc 或者 .bashrc 中加入如下两行:
alias setproxy="export ALL_PROXY=socks5://127.0.0.1:10808"
alias unsetproxy="unset ALL_PROXY"
只对 http 协议生效,比如 curl,wget 等,而对于走 SSH 协议的 git clone git@... 是无效的,也不可以使用 ping 来验证。
git clone§
https
git config --global http.proxy 'socks5://127.0.0.1:10808'
git config --global https.proxy 'socks5://127.0.0.1:10808'
log§
git log --graph --pretty=oneline --abbrev-commit
# --pretty=format:%s
tig§
ncurses-based text-mode interface for Git
sudo apt install tig
FAQs§
server certificate verification failed. CAfile: none CRLfile: none§
使用私人网站或镜像网站作为 Git 服务器时,证书不可信。
git config --global http.sslverify false
git config --global https.sslverify false
当git服务器不支持ssh公钥访问时,保存密码§
不是很安全,文件中将记录明文密码。
git config --global credential.helper store
vim ~/.git-credentials
old mode 100755 new mode 100644§
git config --global core.filemode false
git update-index --chmod=(+|-)x <path>