git 常用操作

设置代理

git config --global http.proxy http://192.168.0.107:7890
git config --global https.proxy https://192.168.0.107:7890

git config --global http.proxy socks5://127.0.0.1:7890
git config --global https.proxy socks5://127.0.0.1:7890

git config --global --add remote.origin.proxy ""

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


// 只针对 github 网站设置代理
git config --global http.https://github.com.proxy https://127.0.0.1:1080
git config --global https.https://github.com.proxy https://127.0.0.1:1080

// 增加缓存
git config --global http.postBuffer 524288000

// 添加到 hosts 末尾
199.232.5.194 github.http://global.ssl.fastly.net
140.82.114.4 github.com

递归 clone

git clone --recursive -b v1.23.0 https://github.com/grpc/grpc

//子模块失败时使用
git submodule update --init --recursive

创建仓库

git init

创建本地用户

git config --local user.name xxx
git config --local user.email xxx@example.com

指定私钥

git config core.sshCommand "ssh -i ..\\blogHome"

追加注释

如果执行了commit 发现注释要修改可以,通过下面命令使用 vim 编辑。

git commit --amend

查看状态

git status

添加当前目录所有改动文件

git add .

提交

git commit -m "xxx"

显示日志

git log

// 获取最后一次提交的时间戳
// %at: author date, UNIX timestamp
git log --format=@%at -1

显示 tag

git tag

获取 tag 代码

git checkout tag

显示本地分支

git branch

切换分支到test

git branch  
* br-2.1.2.2
master
test

git checkout test
git branch
br-2.1.2.2
master
* test

撤销本地修改

git checkout . #本地所有修改的。没有的提交的,都返回到原来的状态
git stash #把所有没有提交的修改暂存到stash里面。可用git stash pop回复。
git reset --hard HASH #返回到某个节点,不保留修改。
git reset --soft HASH #返回到某个节点。保留修改

git clean -df #返回到某个节点
git clean 参数
-n 显示 将要 删除的 文件 和 目录
-f 删除 文件
-df 删除 文件 和 目录

撤销跟踪文件

git rm -r --cached *.sdf