gitlearn

列出配置信息:git config [--global|system|local] -l
配置名字:git config --global user.name '用户名'
配置邮箱:git config --global user.email '邮箱'
删除配置:git config --unset user.name

local 项目级
global 当前用户级
system 系统级

 

修改对比:git diff 文件名

查看版本历史记录:git log --pretty=oneline --abbrev-commit

查看版本操作记录:git reflog

 

// 查看【远程仓库】所有push记录,截止本地已pull的版本(注:数据是从本地读取)
git log --all --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%ci) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative

// --优化简版:
git log --graph --pretty=format:'%C(red)%h - %C(black)%s%C(green)(%ci)%C(blue)<%an>'
git log --oneline --decorate --graph --all --format="%C(red)%h - %C(white)%s - %C(green)%ci - %C(blue)%an"
// 查看【本地】pull记录。 git reflog show origin/main --pretty='format:%C(red)%h%Creset %C(cyan)%gd%Creset %C(green)%gs%Creset: %s' --date=iso

 

到指定标签版本:git reset --hard v1.0

撤销提交(删除版本记录):git revert 版本号

 

查看git远程仓库最近一次更新记录:git show

查看git更新记录:git log

 

window/ios/linux通用命令:

1. git init //初始化仓库
2. git remote add origin 远程仓库地址 //链接远程仓库
3. git fetch // 从远程获取代码库
4. git branch -r/-a //查看分支(不加参数:本地分支,-r:远程仓库分支,-a:所有分支)
5. git checkout 分支名 //切换分支
6. git pull //拉取所有仓库内容,并列出分支信息(origin master 拉取指定分支版本)
7. git add .(文件name) //添加文件到本地仓库
8. git status -s //查看仓库状态
9. git commit -m "first commit" //添加文件描述信息
10.git push //把本地仓库的文件推送到远程仓库(-u origin master 提交本地指定分支版本)
11.git remote -v //查看远程仓库地址/路径

git log --stat -4 // 查看最近4条commit做了哪些改动(文件清单)
git reset --soft HEAD^ //撤销commit
git reset --hard HEAD^ //撤销commit和add
git commit --amend // 修改注释

git diff 文件路径 // 查看文件被修改的内容,配合 git status 使用
11.git branch -D 本地分支名称 //删除本地分支 12.git checkout -- test.html //还原修改的文件 13.git merge 分支名称 //将其他分支合并到当前分支 14.git merge --abort //取消合并 15.git reset --soft/--mixed/--hard ID //三个参数回退程度是依次递进。不重置/改变/重置:工作区和暂存区。 16.git checkout . //当前分支的修改会重置 谨慎使用 17.git clean -n //显示未add的新增文件和文件夹 18.git clean -xdf //清除未add的文件和文件夹,x:无视gitignore文件,f:清除文件,df:清除文件和文件夹 19.//【综合应用】还原至远程主分支(本地所有未push文件将被清除!) git log //查看远程版本(origin) git reset origin版本号 //退回远程版本 git add . //将所有文件 tracked git reset --hard //清除所有 tracked 文件 20.//【综合应用】强行清除本地所有未commit的文件(含untracked) git add . //将所有文件 tracked git reset --hard //清除所有 tracked 文件,不含 commit 文件 21.//【综合应用】【常用】还原未commit的变更文件 git status -s git reset head 路径 //将 tracked 的文件值为 untracked git checkout 目录 //还原目录下的更改 22.//pull时和本地文件冲突 git stash //暂存本地分支 git push //拉取服务器分支 git stash pop //合并暂存的分支,手动解决冲突

 

git中,各个状态的含义:

U  //新增文件,未add
A  //新增的文件,add后
M  //原有文件被修改,或add后被修改

 

标签:

查看本地tag
git tag -l

查看远程tag
git ls-remote --tags origin

// 根据已有分支创建新的分支
git checkout -b yourbranchname origin/oldbranchname


// 推送到git
git push origin yourbranchname


新建本地tag
git tag -a '版本号' -m '备注xxxx'

推送本地tag到远程tag
git push origin [分支] ['tag版本号']    // 不选择分支和版本号时,默认推送关联分支
// 阶段理解:tag相当于一次快照,不能更改,只推送一次即可,不能将新的更改加入到已有的tag中。
推送本地所有tag到远程 git tag origin --tags clone指定tag版本 git clone --branch [tags标签] [git地址] git clone -b 0.0.1 --depth=1 https://github地址 // -b 后面写上指定版本标签 // --depth 表示克隆深度, 1 表示只克隆最新的版本. 因为如果项目迭代的版本很多, 克隆会很慢 删除本地tag git tag -d '版本号' 删除本地所有tag git tag -l | xargs git tag -d 删除远程tag git push origin :refs/tags/版本号 删除远程所有tag git show-ref --tag | awk '{print ":" $2}' | xargs git push origin

 

常见问题:

1、git commit -m 'first commit'
error: pathspec 'commit'' did not match any file(s) known to git.,
解决:windows用双引号,Mac用单引号。

 

2、window 管理git账号

搜索“凭证”,在windows凭证中对Git账户进行管理

 3、Failed to connect to github.com port 443: Timed out

参考:https://blog.csdn.net/qq_41174706/article/details/116004981

步骤: 1、ipaddress.com网站查询IP: 140.82.113.3 github.com 151.101.1.194 github.global.ssl.fastly.net 151.101.65.194 github.global.ssl.fastly.net 151.101.129.194 github.global.ssl.fastly.net 151.101.193.194 github.global.ssl.fastly.net 185.199.108.153 assets-cdn.github.com 185.199.110.153 assets-cdn.github.com 185.199.111.153 assets-cdn.github.com 185.199.109.153 assets-cdn.github.com 2、结果追加到hosts文件末尾。 3、cmd命令:ipconfig /flushdns,刷新DNS。 其他: windows hosts文件地址:C:\Windows\System32\drivers\etc

 

4、remote: Support for password authentication was removed on August xxx

参考文章:https://www.cnblogs.com/helios-fz/p/15903517.html

 

MacOS 常见问题:

1、fatal: repository ' ' not found
解决:
git credential-osxkeychain erase
host=github.com
protocol=https

 

posted @ 2020-03-15 11:12  vv_online  阅读(266)  评论(0编辑  收藏  举报