git学习笔记

git学习笔记

git 缩写配置

  • 在home目录创建.gitconfig文件复制粘贴以下配置并保存退出
[user]
  name = xx
  email = xx@qq.com
[color]
  interactive = auto
  diff = auto
  status = auto
  branch = auto
  ui = true
  repositoryformatversion = 0
  filemode = true
  bare = false
  logallrefupdates = true
  ignorecase = true
  precomposeunicode = false

[alias]
  co = checkout
  ci = commit
  st = status
  sh = stash
  sa = stash apply
  sp = stash pop
  ap = add -p
  br = branch
  cp = checkout -p
  cv = commit -v
  dc = diff --cached
  d = diff
  pr = pull --rebase
  ps = push
  l = log --graph --pretty=format:'%C(yellow)%h%Creset %C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=short --all
  lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --all
[hub]
  protocol = https
[diff]
  tool = vimdiff
[core]
  editor = vim

常用缩写

  • git co
    在这里插入图片描述

  • git br
    在这里插入图片描述

  • git st
    在这里插入图片描述

  • git lg
    在这里插入图片描述

工作流

  1. 开发新功能a
proj1 a 基于proj1分支创建一个a分支(step1) a分支开发完后合并入proj1分支,并删除a分支(step2) proj1 a
step1:
git br a proj1
git push origin a

step2:
git co proj1
git pull
git co a
git merge proj1
git push

git co proj1
git merge a
git push
git br -D a

常用命令

  • 删除远程分支a:
    • 切换到本地其它分支,如master
git co master
  • 删除远程分支
git push origin --delete a
  • 修改远程分支地址
git remote -v
git remote rm origin
git remote add origin git@gitee.com:cfanzp/linux_note.git
  • git添加多个远程分支地址
git remote add gitee git@gitee.com:cfanzp/linux_note.git

git tag

命令作用
git tag查看标签列表
git tag -l “v1.0*”模糊匹配查询
git tag --list “v0.0*”模糊匹配查询
git tag -a v1.0 -m “my version 1.0”添加附注标签
git show v1.0查看标签相关信息
git tag -lw创建轻量标签,git show 不会看到额外标签信息
git tag -a v0.9 9fceb02后期打标签
git push origin --tags将标签推送到远端
git tag -d v1.0删除标签
git push origin --delete 删除远端标签

git diff

命令作用
git diff查看差异
git diff cached查看工作版本和暂存的差异
git diff HEAD查看工作版本和HEAD的差异
git diff HEAD^ HEAD查看上上个版本和HEAD的差异
git diff --stat查看差异的文件列表
git diff --stat ./client查看client目录 差异的文件列表
git diff > patch使用git diff 打补丁
git apply --check patch使用补丁,没有任何输出表示可以顺利接受这个补丁
git apply --reject patch使用补丁,冲突会生成.rej文件

git 回退到某个版本

  1. git reset commit-id
  2. git push origin branch-name --force

远程分支更新

  1. git remote update origin --prune

删除所有历史commit,创建一个新仓库

  1. Checkout
   git checkout --orphan latest_branch
  1. Add all the files
   git add -A
  1. Commit the changes
   git commit -am "commit message"
  1. Delete the branch
   git branch -D master
  1. Rename the current branch to master
   git branch -m master
  1. Finally, force update your repository
   git push -f origin master
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

打杂程序员

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值