设置或查看用户名和邮箱
- 查看全局配置:git config --global -l
- 修改全局的用户名和邮箱:
- git config --global user.name "用户名"
- git config --global user.email "邮箱“
- 查看局部配置:git config --local -l
- 修改局部的用户名和邮箱:
- git config --local user.name "用户名"
- git config --local user.email "邮箱"
清除用户名
git config --global credential.helper wincred
git credential-manager uninstall
存储用户名密码
// 输入命令后 再次输入用户名密码之后就可以保存
git config --global credential.helper store
撤销commit
commit 后没有push,想要撤销commit
git reset --soft HEAD^
回退版本
reset
- 回退到上一个版本:git reset --hard HEAD^(HEAD^^上上个版本,以此类推)
- reset之后,之前的版本就看不到了,若要找回,可以通过:git reflog查看日志;
借鉴文章:www.liaoxuefeng.com/wiki/896043… 并且使用命令进行回退:git reset --hard 1a2552b
远程库做了回退后提交
- 回退后提交:git push (版本比远程库要旧会报错)
- 回退后强提交:git push -f
revert
原理: git revert是用于“反做”某一个版本,以达到撤销该版本的修改的目的。比如,我们commit了三个版本(版本一、版本二、 版本三),突然发现版本二不行(如:有bug),想要撤销版本二,但又不想影响撤销版本三的提交,就可以用 git revert 命令来反做版本二,生成新的版本四,这个版本四里会保留版本三的东西,但撤销了版本二的东西 (原文链接:blog.csdn.net/yxlshk/arti…)
- 回退命令:git revert -n 版本号 (修改冲突)
文件过大上传失败
remote: error: File android/java_pid81583.hprof is 536.13 MB; this exceeds GitHub's file size limit of 100.00 MB exceeds GitHub's file size limit of 100.00 MB
修改方法:删除大文件android/java_pid81583.hprof
git filter-branch --force --index-filter "git rm --cached --ignore-unmatch android/java_pid81583.hprof" --prune-empty --tag-name-filter cat -- --all
// 删除完成之后可以修改日志
git commit --amend
// 修改完成可以再次提交
git push
删除分支
- 删除本地分支:git branch -d 分支名称(主要要切换到其他分支)
- 删除远程分支:git push origin --delete 分支名称
为git打tag
- git查看tag的命令是:git tag
- 创建Tag 是直接加名字就ok了,格式: git tag tag名称 –m "注释"
- 推送到远端 git push origin tag名称
设置ss
- git config --global http.proxy 'socks5://127.0.0.1:1080'
- git config --global https.proxy 'socks5://127.0.0.1:1080'
设置代理
- git config --global https.proxy 'http://127.0.0.1:1080'
- git config --global https.proxy 'https://127.0.0.1:1080'
取消代理
- git config --global --unset http.proxy
- git config --global --unset https.proxy
git识别文件大小写
git config core.ignorecase false
git删除缓存文件夹和下面的文件
git rm -rf --cache 需要删除的文件夹名称
修改git地址
git remote set-url 项目名称 git@地址:名称.git