【Git】关于git 个人使用笔记

11 篇文章 0 订阅

项目开发中需要用到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

https://blog.csdn.net/ys_230014/article/details/81505800

https://www.cnblogs.com/PeunZhang/p/11649910.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值