项目开发中需要用到git版本管理,但是很多命令不常用,出现记不住的情况,特此记录下来,做个备忘录。
git命令使用笔记
#git 命令行
-------------------------------------------------------
[version]
git --version # 查看当前git版本
[help]
git help # git 帮助命令
git help <verb> # git 具体帮助命令
[config]
git config --global alias.lg "log --pretty=format:'%ad %an %s' --author name"
# 设置git log的别名为 git lg
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
git config --list # git 配置列表
git config help # 弹出网页对当前命令的说明
git config --global user.name # 设置用户名称
git config --global user.email # 设置邮箱
git config user.name # 查看当前用户
git config user.email # 查看当前邮箱
git config --global core.autocrlf # 设置字符编码
git config --global core.qutoepath false # 设置中文字符显示命令
git config --global i18n.commitencoding utf-8 # 设置提交命令的时候使用utf-8编码集提交
git config --global i18n.logoutputencoding utf-8 # 日志输出时使用utf-8编码集显示
export LESSCHARSET=utf-8 # 设置LESS字符集为utf-8
-------------------------------------------------------
git init # 初始化仓库
git clone https://xxx.git # 克隆远程仓库
git pull # 更新当前仓库
git fetch # 从远程仓库抓住
[status]
git status # 当前仓库下的文件状态提示
git status ./ # 当前仓库下的文件状态
git diff # 查看当前的工作
[log]
git log # 查看日志
git reflog # 查看全部日志
[add]
git add . # 添加所有文件到暂存
git add -A # 添加所有文件到暂存
git add ./* # 添加所有文件到暂存
git add path/file.txt # 添加指定文件到暂存
[remote]
git remote -v # 查看远程仓库地址
git remote rm origin # 删除远程关联仓库
git remote add origin https://xxx.git # 重新关联远程仓库
[commit]
git commit -m 'commit message' # 提交命令[描述内容]为必填
git commit -a -m 'commit message' # 已加入版本的文件直接提交,不用git add
git commit i -m 'commit message' file.txt # 解决冲突在此提交
[push]
git push -u origin master # 推送仓库
git push -f origin master # 强制推送到远程仓库
[checkout]
git checkout . # 放弃所有文件修改
git checkout -f # 将暂存区的文件撤销
git checkout filepath/filename # 撤销对某一文件的修改
git checkout --filename # 放弃对某一文件的修改
[reset]
git reset # 恢复
git reset HEAD # 恢复全部文件
git reset --hard # 恢复到上一个版本
git reset --hard HEAD^ # 已add且commit 可使用 此命令
git reset --hard [version number] # 恢复到某一版本
[branch]
git branch # 查看本地分支
git branch -r # 查看远程分支
git branch -a # 查看所有分支(本地和远程)
git branch -vv # 查看当前分支
git config --lis # 查看当前分支配置
git branch [branch name] # 创建新的分支
git branch -b [branch name] # 创建分支并切换到该分支
git checkout [branch name] # 切换分支
git checkout -f [branch name] # 强行切换分支
git push origin [branch name] # 推送分支到远程仓库
git branch -d [branch name] # 删除本地分支
git push origin :[branch name] # 删除远程分支 分支前的冒号代表删除
git push origin [branch name] # 推送到分支仓库
git rebase [branch name] #
git merge [branch name] # 合并分支
参考资料
https://blog.csdn.net/top_code/article/details/51931916