git操作指南


git强行还原

有时候自己对仓库做了修改,但不需要这些修改,可以强行还原。

git fetch --all && git reset --hard origin/stable && git pull

git初始化子模块

参考:Git - 子模块
参考:git submodule init does absolutely nothing - Stack Overflow
参考:github - How to link folder from a git repo to another repo? - Stack Overflow

git submodule update --init --recursive

git 配置代理

有时候公司内网不能直连外网,需要配置git的网络代理。

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

git 单仓库配置多个远程仓库

我在GitHub和coding上都建了仓库,想单次push到2个仓库,于是需要设置remote

git remote add all https://xxx.xxxx.git
$ git remote -v
all     https://e.coding.net/xxxx.git (fetch)
all     https://e.coding.net/xxxx.git (push)
origin  https://github.com/xxxx.git (fetch)
origin  https://github.com/xxxx.git (push)
git push all master

参考:github - Git - Pushing code to two remotes - Stack Overflow

git 设置/重置用户名和密码

有时候输入的用户名或者密码错误了,但git已经保存了,无法直接更改。

一种方法是直接删除用户,再输入:

git config --global --unset user.password

如果是Windows用户,可以在如下位置找到保存的密码:
Control Panel->All Control Panel Items->Credential Manager->Windows Credentials
或者直接搜索凭据管理器,可以直接修改用户名和密码。

参考:macos - How do I update the password for Git? - Stack Overflow


Git操作参考:Git的奇技淫巧
有一篇好文章:一篇文章,教你学会Git

在这里插入图片描述

每次commit,git存储的是全新的文件快照而不是文件的变更部分。这是做了一个取舍,这样每次在切换分支的时候,读取文件是O(1)的时间复杂度,而不是O(N)的时间复杂度。

git误操作如何恢复
使用git reflog,修改HEAD的指针

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值