Git 常用命令行
Create a new repository
git clone xxx.git
cd [folder]
git push -u origin master
切换账号
- 查看账号信息
git config --global --list
git config --global -l
- 更改全局账号
git config --global user.name "Carina"
git config --global user.name "15xxxxx584@qq.com"
- 更改本地账号
git config --local user.name "Carina"
git config --local user.name "15xxxxx584@qq.com"
config
- 重置
git配置
git config --global --unset https.proxy
Github 配置 SSH key
- 设置用户名和邮箱
在git命令行中对git进行全局设置
git config --global user.name "用户名"
git config --global user.email "邮箱地址"
- 生成
SSH key在git命令行中,输入命令:
cd ~/.ssh
来检测是否生成过key,没有生成过key,会有相关信息提示;然后输入命令:
ssh-keygen -t rsa -C "邮箱地址"
按下回车键;然后根据返回的信息,找到 .ssh 目录下的两个文件;
-
在
github上添加SSH key -
检查
SSH key是否有效
ssh -T git@github.com
分支
远程仓库
git remote -v 查看远程仓库
git remote rm origin 删除远程仓库
git remote add origin <仓库地址> 添加远程仓库
修改全局默认分支
git config --global init.defaultBranch main
列出所有本地分支
git branch
列出所有远程分支
git branch -r
列出所有本地分支和远程分支
git branch -a
新建一个分支,但依然停留在当前分支
git branch [branch-name]
以远程分支为基础新建一个分支,并切换到该分支
git checkout -b [branch] origin/[remote-branch]
新建一个分支,指向指定commit
git branch [branch] [commit]
新建一个分支,与指定的远程分支建立追踪关系
git branch --track [branch] [remote-branch]
切换到指定分支,并更新工作区
git checkout [branch-name]
切换到上一个分支
git checkout -
建立追踪关系,在现有分支与指定的远程分支之间
git branch --set-upstream [branch] [remote-branch]
合并指定分支到当前分支
git merge [branch]
选择一个commit,合并进当前分支
git cherry-pick [commit]
删除分支
git branch -d [branch-name]
删除远程分支
git push origin --delete [branch-name]
git branch -dr [remote/branch]
代码提交到了错误的分支
git checkout [错误的分支]
git log [q退出编辑]
git reset HEAD~1
git stash
git checkout [应该提交代码的分支]
git stash pop
回滚项目版本
git reset --hard d12s11a5s16
git push -f /* 强制推送 */
导出差异文件
git log --pretty=oneline /* 查看版本之间 commit 的 id */
git diff [old version] [new version] --name-only | xargs zip update.zip /* xargs 是 Linux 命令 */
在 Windows 下使用 Linux 命令
使用过linxu的伙计估计都会喜欢上linux各种各样强大的命令如:grep, sed,awk,diff和patch。cygwin是一个windows下的linux模拟器,对于想在windows下使用linux命令的人来说是一个选择。但是cygwin过于复杂庞大,下载比较费劲,本人最终没有下载,也没有用过。个人感觉GunWin32是一个不错的选择,GnuWin32使windows用户可以在命令行窗口中使用各种各样的linux命令,就跟使用普通的windows命令一样简单。
-
下载GnuWin32,GnuWin32的安装文件(GetGnuWin32-0.6.3.exe)下载地址:sourceforge.net/projects/ge…
-
运行GetGnuWin32-0.6.3.exe,并指定安装目录。
-
进入安装目录的GetGnuWin32子目录,GetGnuWin32子目录是GetGnuWin32-0.6.3.exe自动建立的
-
运行download.bat,这个过程会从网络上下载所有linux命令程序,所以需要等待很长时间,大家可以出去打打酱油什么的
-
运行install.bat,到此安装结束,大家可以开始使用各种linux命令了。
命令使用方法: 1. find + grep 查找指定文件: find D:\* | grep.xml 2. type/cat + grep 过滤文件内容:cat test.txt | grep KEY2 或 type test.txt | grep KEY2 3. sed删除文件内容:cat test.txt | sed "s/\[KEY2\] //" 4. iconv转换文件编码:iconv -f gbk -t utf-8 史上第一掌门.txt > 史上第一掌门_utf-8.txt 5. 图片格式转换格式jpeg到pnm: jpegtopnm cat_type_grep.jpg > cat_type_grep.jpg.pnm 6. 图片格式转换格式pnm到png: pnmtopng cat_type_grep.jpg.pnm > cat_type_grep.png 7. 图片格式转换格式jpeg到png: jpegtopnm cat_type_grep.jpg | pnmtopng > cat_type_grep.png 8. 批量转化图片:for /r .\ %i in (*.jpg) do jpegtopnm %i | pnmtopng > %~ni.png
Git 提交规范
feat: A new feature(新增feature)
fix: A bug fix(修复bug)
docs: Documentation only changes(仅文档更改,如README.md)
refactor: A code change that neither fixes a bug nor adds a feature(代码重构,没有新增功能或修复bug)
perf: A code change that improves performance(优化相关,如提升性能、用户体验等)
test: Adding missing tests or correcting existing tests(测试用例,包括单元测试、集成测试)
build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)(影响构建系统或外部依赖关系的更改(示例范围:gulp、broccoli、npm))
chore: Other changes that don't modify src or test files(其他不修改src或测试文件的更改) improvement: An improvement to a current feature(对当前特性的改进)
style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)(不影响代码含义的更改(空格、格式、缺少分号等))
ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)(对ci配置文件和脚本的更改)
revert: Reverts a previous commit(还原以前的提交)