暂存

git stash save "save message" #暂存当前作业
git stash list # 查看当前暂存
git stash show (stash@{$num})    # 查看有哪些改动
git stash show (stash@{$num}) -p # 查看暂存具体改动
git stash apply (stash@{$num})   # 应用某个暂存
git stash pop (stash@{$num})     # 恢复某个暂存
git stash drop (stash@{$num})    # 删除某个暂存
git stash clear # 清除所有暂存

proxy

git config --global http.proxy "http://127.0.0.1:8080"
git config --global https.proxy "http://127.0.0.1:8080"

取消设置

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

SSH proxy

修改 ~/.ssh/config 文件(不存在则新建):

~/.ssh/config
# 必须是 github.com
Host github.com
   HostName github.com
   User git
   # 走 HTTP 代理
   # ProxyCommand socat - PROXY:127.0.0.1:%h:%p,proxyport=8080
   # 走 socks5 代理(如 Shadowsocks)
   # ProxyCommand nc -v -x 127.0.0.1:1080 %h %p

submodule

参考 7.11 Git 工具 - 子模块

在 clone 的时候初始化:

git clone --recurse-submodules https://github.com/chaconinc/MainProject

如果忘了 pull 的时候初始化,可以在项目里初始化子模块

git submodule update --init --recursive

rebase

格式

git rebase -i <COMMIT_HASH> # COMMIT_HASH 为 rebase 位置

branch

git push origin --delete master # 删除远程分支
git branch -r # 查看远程分支
git checkout -b branch origin/branch # 切换到远程分支

LFS clone

在 clone 一个带 LFS 的文件的时候报错:

$ git clone https://github.com/robertcsapo/cisco-ios-xe-ubuntu.git
Cloning into 'cisco-ios-xe-ubuntu'...
... ...
Error downloading object: ... ...: batch response: This repository is over its data quota. Account responsible for LFS bandwidth should purchase more data packs to restore access.

参考这个 issue

  1. Fork the repo to one of your users
  2. Go to repo settings
  3. Find “Include Git LFS objects in archives” under the Archives section and check it
  4. Go to the Danger Zone section, select “Archive this repository”
  5. Confirm and authorize.
  6. Return to the archived repository.
  7. Download as .zip
  8. Download will pause for a minute or so before it starts downloading lfs objects. Wait and it should continue.