惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The GitHub Blog
The GitHub Blog
K
Kaspersky official blog
Stack Overflow Blog
Stack Overflow Blog
Blog — PlanetScale
Blog — PlanetScale
Recorded Future
Recorded Future
Engineering at Meta
Engineering at Meta
U
Unit 42
D
Docker
I
InfoQ
D
DataBreaches.Net
Google DeepMind News
Google DeepMind News
N
Netflix TechBlog - Medium
C
Check Point Blog
The Cloudflare Blog
美团技术团队
V
Vulnerabilities – Threatpost
博客园_首页
T
Threat Research - Cisco Blogs
Google DeepMind News
Google DeepMind News
Attack and Defense Labs
Attack and Defense Labs
A
Arctic Wolf
IT之家
IT之家
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
T
Troy Hunt's Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
人人都是产品经理
人人都是产品经理
C
Cyber Attacks, Cyber Crime and Cyber Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Security Archives - TechRepublic
Security Archives - TechRepublic
S
Schneier on Security
Apple Machine Learning Research
Apple Machine Learning Research
MyScale Blog
MyScale Blog
P
Privacy International News Feed
云风的 BLOG
云风的 BLOG
Recent Commits to openclaw:main
Recent Commits to openclaw:main
T
The Blog of Author Tim Ferriss
GbyAI
GbyAI
The Last Watchdog
The Last Watchdog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
aimingoo的专栏
aimingoo的专栏
P
Proofpoint News Feed
The Register - Security
The Register - Security
博客园 - 三生石上(FineUI控件)
Forbes - Security
Forbes - Security
NISL@THU
NISL@THU
Y
Y Combinator Blog
T
Threatpost
Microsoft Azure Blog
Microsoft Azure Blog
L
Lohrmann on Cybersecurity

博客园 - 马会东

Llama3 在HumanEval中的表现 在 Apple Silicon Mac(M1、M2 或 M3)上运行最新 LLM 模型 Meta Llama 3 的分步指南 mamp nginx thinkphp5 配置方法 centos8 yum 安装rabbitmq dotnet new 命令 ACE Editor(代码编辑器) 入门教程 在mac上使用docker部署Mongo数据库 如何在Curl中使用Socks5代理 知识付费平台 快速开发框架(管理系统-持续更新) mysql 索引优化原则总结(limit where in like ) MySQL高级知识——Order By关键字优化 mysql索引的排列顺序 解决MySQL使用limit偏移量较大效率慢的问题 tar命令详解 systemctl命令列出所有服务 使用git时显示untracked files(未监控)解决办法 MySQL中Case When用法详解 计算机指令-流水线和吞吐率
Git的撤销、修改和回退命令
马会东 · 2022-11-08 · via 博客园 - 马会东

一、撤销修改(git add/rm 之前)

1

2

git checkout -- *   //是撤销从上次提交之后所做的所有修改

git checkout -- filaname  //是撤销从上次提交之后的单个文件的修改

二、git add/rm 之后,还未git commit

情况一:

从暂存区撤出

1

2

git reset HEAD <file>  //reset 某个文件

git reset HEAD .       //reset 所有

情况二:

如果是 git rm 的文件,需要执行下面的,把它撤回来,add 的文件不能用(用了会撤回修改,如果想撤回修改前的,也可以用下面的命令)

1

2

git  checkout -- file_name

//注:如果执行 git checkout -- . 则会把之前add 更改的文件也给撤回了

三、撤销修改 git commit -m ""  、还未执行git push

1. 找到上次git commit的 id,找到你想撤销的commit_id

2. 完成撤销,同时将代码恢复到前一commit_id 对应的版本

1

git reset --hard commit_id   //执行撤销

注:不保留commit 之前修改的代码,reset之后,代码回滚到上个版本
3.完成Commit命令的撤销,但是不对代码修改进行撤销,可以直接通过git commit 重新提交对本地代码的修改。

1

git reset commit_id  //注释

注:保留commit之前修改的代码,撤销后,代码是修改后的状态,还能继续修改

四、对于已经push的版本,进行回退

1、第一步:

1

git reset --hard 版本号 //本地回退到指定的版本

2、第二步:

1

git push -f origin dev //将远程的也回退到指定版本

到此这篇关于Git的撤销、修改和回退命令的文章就介绍到这了。希望对大家的学习有所帮助,也希望大家多多支持脚本之家。