git操作命令

1. 更新git版本

git --version # 查看git版本

sudo apt update  # 更新源
sudo apt install software-properties-common # 安装 PPA 需要的依赖
sudo add-apt-repository ppa:git-core/ppa    # 向 PPA 中添加 git 的软件源
sudo apt-get update
sudo apt-get install git

2. git revert

git revert -n commit_id         # 将已提交的代码回退到暂存区
git revert commit_id            # 将已提交的代码回退掉并commit,先选择Y,再选择EXIT

3. git reset

git reset --hard HEAD^         # 撤销并删除commit
git reset --soft HEAD^         # 插销commit到add
git reset HEAD filename        # 撤销add

4. git diff

git diff file_name             # 查看暂存之前的更改
git diff --staged file_name    # 查看暂存区的更改
git diff --cached file_name    # 查看暂存区的更改

5. git config

git config --global i18n.logoutputencoding utf-8     # 设置git log 中文格式为UTF-8
git config --global core.quotepath false             # git status时中文路径变成数字
git config --global gui.encoding utf-8               # 设置gitk格式为UTF-8
git config --global i18n.commit.encoding utf-8       # 设置commit格式为UTF-8
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
set fileencodings=utf-8
set termencoding=utf-8
set encoding=utf-8
$ git config --global core.quotepath false          # 显示 status 编码
$ git config --global gui.encoding utf-8            # 图形界面编码
$ git config --global i18n.commit.encoding utf-8    # 提交信息编码
$ git config --global i18n.logoutputencoding utf-8  # 输出 log 编码
$ export LESSCHARSET=utf-8
# 最后一条命令是因为 git log 默认使用 less 分页,所以需要 bash 对 less 命令进行 utf-8 编码

6. git branch

git branch -d master        # 删除本地分支
git branch -D 分支名称       # 强制删除本地分支
git branch                  # 列出本地已经存在的分支,并且当前分支会用*标记
git branch -r               # 查看远程版本库的分支列表
git branch -a               # 查看所有分支列表(包括本地和远程,remotes/开头的表示远程分支)
git branch -v               # 查看一个分支的最后一次提交
git branch --merged         # 查看哪些分支已经合并到当前分支
git branch --no-merged      # 查看所有未合并工作的分支
git branch 新分支名称        # 创建分支

7. git stash

git stash                     # 隐藏暂存区文件,新增文件不会被存储.
git stash save "jack"         # stash并命名为jack
git stash –keep-index         # stash没有add的文件
git stash list                # 查看stash了哪些内容
git stash show                # 显示做了哪些改动,和git log 内容较像
git stash show stash@{num}    # 显示第num次做了哪些改动
git stash show stash@{num} -p # 显示第num次做了哪些改动,和git diff
git stash apply               # 应用某个存储,但不会把存储从存储列表中删除,默认使用第一个存储 stash@{0},第二个:git stash apply stash@{1} 
git stash pop                 # 应用某个存储,同时把存储从存储列表中删除,默认使用第一个存储 stash@{0},第二个:git stash pop stash@{1}
git stash drop stash@{$num}   # 丢弃stash@{$num}存储,从列表中删除这个存储
git stash clear               # 删除所有缓存的stash

8. git checkout

git checkout 分支名称 # 切换分支
git checkout -b 新分支名称  # 创建分支的同时,切换到该分支上

9. git push

git push origin :分支名称             # 删除远程分支,分支名称前有个冒号,分支名前的冒号代表删除

10. git配色

git config --global color.status auto 
git config --global color.diff auto 
git config --global color.branch auto 
git config --global color.interactive auto
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值