Allen's blog Allen's blog
首页
面经
算法 (opens new window)
分类

Allen

前端CV工程师
首页
面经
算法 (opens new window)
分类
  • shadowsocks代理架构

  • 博客搭建

  • 数据结构与算法

  • Git

    • Git常用命令快速查找
      • 生成 ssh 密钥
      • 添加 Git 基本配置
      • 修补提交
      • 查看提交历史
      • 添加远程仓库
      • 分支操作
      • 暂存代码 stash
      • 回撤、回滚
      • 变基 Rebase
      • 打标签 Tag
    • 初始(全局)配置
    • 代码回撤与回滚
    • 远程仓库
    • 分支管理
    • Git忽略文件语法
  • 其他技术
  • Git
Allen
2023-02-16
目录

Git常用命令快速查找

参考文章:Pro Git (opens new window)、Mr.Hope Git 教程 (opens new window)、廖雪峰 Git 教程 (opens new window)

# 生成 ssh 密钥

ssh-keygen -t rsa -C +邮箱
1

# 添加 Git 基本配置

git config add user.name="xxx"
git config add user.email="xxx"
git config --global pull.rebase true // Merge branch 'dev' of ...
1
2
3

# 修补提交

# 查看提交历史

# 查看提交历史
git log --graph --pretty=oneline --abbrev-commit
# 查看使用过的命令
git reflog
1
2
3
4

# 添加远程仓库

git remote add origin https://xxxxx.git
1

# 分支操作

建立本地分支和远程分支链接:git branch --set-upstream-to <branch-name> origin/<branch-name>

查看分支:git branch

查看本地和远程分支:git branch -vv

新建分支:git branch dev

切换分支:git checkout dev

创建并切换分支:git checkout -b dev

在本地创建和远程分支对应的分支,使用 git checkout -b branch-name origin/branch-name

本地创建并跟踪远程分支:git checkout --track origin/远程分支名

删除分支:git checkout -d fix

强制删除分支:git checkout -D fix //如果被删除的分支没有进行过合并,则需要强制删除

合并某分支到当前分支:git merge --squaze issue-111 // --squaze 参数会合并 issue-111 的所有提交为一个

只提取一个或几个提交合并:git cherry-pick commitId1 commidId2 ...

# 暂存代码 stash

查看暂存列表:git stash list

暂存代码名为当前提交信息:git stash

暂存并自定义命名:git stash save xxx

取出上一次暂存代码并保留暂存:git stash apply

取出上一次暂存代码并丢弃暂存:git stash pop

取出特定的暂存代码:git stash apply stash@{0}

删除特定的暂存代码:git stash drop stash@{0}

清空 stash:git stash clear

# 回撤、回滚

修补提交

git commit -m 'initial commit'
git add forgotten_file
git commit --amend
1
2
3

回撤到 commitId,不保留暂存区和工作区:git reset --hard commitId // commitId 也可以写HEAD、HEAD^等

回撤到 commitId,保留暂存区和工作区:git reset --soft commitId

回撤到 commitId,保留工作区(默认):git reset --mixed commitId

撤销某次普通提交的修改:git revert commitId

撤销某次合并提交的修改:git revert -m 1 commitId // -m 选项接受的是一个数字,取值为 1、2,含义是保留某个分支

# 变基 Rebase

将本地没有提交到远程的分支的提交历史整理成直线:git rebase/git rebase master

尽量不要 rebase 远程的分支

# 打标签 Tag

查看所有标签:git tag

新建一个标签,默认 HEAD,也可以指定 commitId:git tag <tagname> / git tag v0.9 f523c633

新建标签,指定标签信息:git tag -a <tagname> -m "blablabla..."

推送标签到远程:git push origin <tagname>

推送全部未推送过的本地标签:git push origin --tags

删除一个本地标签:git tag -d <tagname>

删除一个远程标签:git push origin :refs/tags/<tagname>

上次更新: 2023/12/16, 09:22:46
移除元素
初始(全局)配置

← 移除元素 初始(全局)配置→

最近更新
01
rollup使用配置文件rollup.config.ts打包
12-08
02
package.json导出类型
12-08
03
关键问题方案
11-17
更多文章>
Theme by Vdoing | Copyright © 2023-2023 Allen | Github
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式