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
相关推荐
南果梨15 小时前
OpenClaw 完整教程!从安装到使用(官方脚本版)
前端·git·开源
武子康21 小时前
大数据-240 离线数仓 - 广告业务 Hive ADS 实战:DataX 将 HDFS 分区表导出到 MySQL
大数据·后端·apache hive
Selicens2 天前
git批量删除本地多余分支
前端·git·后端
字节跳动数据平台2 天前
5000 字技术向拆解 | 火山引擎多模态数据湖如何释放模思智能的算法生产力
大数据
武子康2 天前
大数据-239 离线数仓 - 广告业务实战:Flume 导入日志到 HDFS,并完成 Hive ODS/DWD 分层加载
大数据·后端·apache hive
闲云一鹤3 天前
Git LFS 扫盲教程 - 你不会还在用 Git 管理大文件吧?
前端·git·前端工程化
字节跳动数据平台3 天前
代码量减少 70%、GPU 利用率达 95%:火山引擎多模态数据湖如何释放模思智能的算法生产力
大数据
得物技术3 天前
深入剖析Spark UI界面:参数与界面详解|得物技术
大数据·后端·spark
武子康3 天前
大数据-238 离线数仓 - 广告业务 Hive分析实战:ADS 点击率、购买率与 Top100 排名避坑
大数据·后端·apache hive
武子康4 天前
大数据-237 离线数仓 - Hive 广告业务实战:ODS→DWD 事件解析、广告明细与转化分析落地
大数据·后端·apache hive