GIT常用命令

git命令

git config --global user.name 名字

git config --global user.email 邮箱

$ git clone 地址

命令 作用
git pull origin master 拉取更新
git checkout 切换分支
git add 文件名 添加到暂缓区
git commit -m "备注" 提交到本地库
git push origin dev-cyw/master 推送到远程仓库
git reflog 查看历史记录
shell 复制代码
# 添加远程仓库
$ git remote add origin 网址xxx
#从远程仓库克隆
$ git clone 网址xxx

# 新建仓库
$ git init xxx

# 从已存在的文件夹创建
$ cd xxx
$ git init

# 添加到暂存区
$ git add <. / filename>
# 撤销
$ git reset HEAD <filename>

#查看本地库状态
$ git status

# 提交到本地仓库
$ git commit --m "备注"
# 还原到上个版本
$ git reset --soft HEAD^

# 推送到远程仓库
$ git push <远程主机> <本地分支>:<远程分支>
$ git push origin master

# 拉取更新
$ git pull <远程主机> <本地分支>:<远程分支>
$ git pull origin master 

# 查看历史记录
$ git reflog

# 删除远程仓库
git push <remote_name> --delete <branch_name>
#eg:git push origin --delete feature-branch
shell 复制代码
# 新建分支
$ git branch (-b) <branchname>

# 切换分支
$ git checkout <branchname>

# 分支列表
$ git branch

# 合并分支
$ git merge <branchname>

# 删除分支
$ git branch -d <branchname>

# 强制删除分支
$ git branch -D <branchname>

补充

修改提交备注:

执行 git commit --amend 命令,修改 commit 信息

1.按i进入编辑,:wq保存退出

2.执行 git push --force origin branch 命令,将修改后的 commit 推送到远程分支。

需要注意的是,使用 git push --force 命令会覆盖远程分支中的历史记录,因此需要谨慎操作。

取消上一次commit

使用 git reflog 查找撤销操作之前的 HEAD 位置: git reflog 命令会显示你的 HEAD 指针的历史记录,包括所有的提交和重置操作。你可以找到执行 git reset 之前的 HEAD 位置的哈希值。

bash 复制代码
git reflog

然后,你可以使用 git reset 命令将 HEAD 指针重置回那个位置:

bash 复制代码
git reset --hard <commit_hash>

撤销上一次远程提交

复制代码
git reset --soft HEAD~1
git push origin xxx-dev --force
相关推荐
得物技术2 天前
从埋点需求到规则资产:Hermes Agent 重构得物数仓工作流
大数据·llm·ai编程
深海鱼在掘金2 天前
Git 完全指南 —— 第1章:Git 概览与版本控制演进
git
久美子2 天前
AI驱动数仓建设的Harness工程实践——本体建模、知识分层与上下文工程
大数据
大树882 天前
金刚石散热越强,管路越先见顶
大数据·运维·服务器·人工智能·ai
大志哥1232 天前
ES和Logstash日志链路系统上线后遭遇切片爆炸(解决)
大数据·elasticsearch
果丁智能2 天前
物联网智能锁赋能集中式住宿:身份核验与远程权限管控的全链路技术实践
大数据·人工智能·物联网·智能家居
ApacheSeaTunnel2 天前
实战演示 | 基于 Apache SeaTunnel 与 Apache DolphinScheduler 实现 MySQL 到 Doris 离线定时增量同步
大数据·mysql·开源·doris·数据集成·seatunnel·数据同步
weixin_397574092 天前
PDF复杂表格的1:1还原引擎:跨页表格自动拼接技术实战
大数据·人工智能·pdf
极光代码工作室2 天前
基于数据仓库的电商数据分析平台
大数据·hadoop·python·spark·数据可视化
noravinsc2 天前
关于Git Flow
git