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

推荐订阅源

T
Troy Hunt's Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
T
Threat Research - Cisco Blogs
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Schneier on Security
Schneier on Security
Scott Helme
Scott Helme
L
LINUX DO - 热门话题
Help Net Security
Help Net Security
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Palo Alto Networks Blog
P
Privacy International News Feed
AWS News Blog
AWS News Blog
Forbes - Security
Forbes - Security
N
News and Events Feed by Topic
L
LINUX DO - 最新话题
A
Arctic Wolf
Hacker News: Ask HN
Hacker News: Ask HN
P
Proofpoint News Feed
N
News and Events Feed by Topic
S
Security @ Cisco Blogs
Cyberwarzone
Cyberwarzone
Google Online Security Blog
Google Online Security Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
PCI Perspectives
PCI Perspectives
Know Your Adversary
Know Your Adversary
The Hacker News
The Hacker News
www.infosecurity-magazine.com
www.infosecurity-magazine.com
T
Tenable Blog
S
Security Affairs
P
Privacy & Cybersecurity Law Blog
W
WeLiveSecurity
Jina AI
Jina AI
The GitHub Blog
The GitHub Blog
S
Securelist
AI
AI
Latest news
Latest news
T
The Blog of Author Tim Ferriss
Application and Cybersecurity Blog
Application and Cybersecurity Blog
C
Cybersecurity and Infrastructure Security Agency CISA
月光博客
月光博客
酷 壳 – CoolShell
酷 壳 – CoolShell
C
CXSECURITY Database RSS Feed - CXSecurity.com
美团技术团队
G
GRAHAM CLULEY
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Simon Willison's Weblog
Simon Willison's Weblog
Hacker News - Newest:
Hacker News - Newest: "LLM"
C
Cisco Blogs
V
Visual Studio Blog
L
LangChain Blog

博客园 - volnet(可以叫我大V)

OpenAI CLIP 关键点 - 连接图像和文字 【笔记】跟吴恩达和IsaFulford学提示词工程(初级开发者入门课程) MacOS使用Charles抓去HTTPS数据 在浏览器的JavaScript里new Date().toUTCString()后,传递给C# DateTime().TryParse()会发生什么? 如何安装Docker UCP Git凭证存储(简单易懂,一学就会,认真看) - volnet(可以叫我大V) - 博客园 重启Ubuntu后Hadoop的namenode起不来的解决办法‬ ASP.NET 上传文件最大值调整 MVC模式下如何实现RegisterStartupScript等功能 RESTful接口设计原则/最佳实践(学习笔记) 如何编译MongoDB? 《硅谷之谜》读书笔记 Google的Bigtable学习笔记(不保证正确性) 软件开发到底是怎么一回事呢? 如何控制自己之2016个人目标管理 如何自适应网页的协议(http/https/……) 数据库时间戳设计 AngularJS-Controller的使用-读书笔记 FIM相关报错汇总
Git撤销提交
volnet(可以叫我大V) · 2016-06-02 · via 博客园 - volnet(可以叫我大V)

本文链接:http://volnet.github.io/#!docs/git/reset-to-old-version.md

在使用Git进行版本管理的时候,经常会遇到一些错误的提交。

在开始演示之前,我们先建立一个测试的环境。

mkdir gittest
cd gittest
git init

echo "a" >> a.md
git add .
git commit -m "add a.md"

echo "b" >> b.md
git add .
git commit -m "add b.md"

echo "c" >> c.md
git add .
git commit -m "add c.md"

rm -rf a.md
git add .
git commit -m "remove a.md"

git remote add origin http://gitserver-url

方法一:git revert(推荐)

推荐理由:git revert将保留commit历史。假设有a、b、c三次顺序提交,那么假设被回滚到a,则b、c仍然存在,同时会多出d。

git log --oneline

931568f remove a.md
f622cef add c.md
2a0c5a9 add b.md
6fbba34 add a.md

# 假设要回到2a0c5a9

git revert -n 2a0c5a9..931568f

# ls可以看到工作目录中的文件已经恢复到当时的状态,这个时候查询git status将看到 2a0c5a9 commit前的状态。

# 这时候需要重新提交文件

git commit -m "revert 2a0c5a9..931568f and recommit"

git push

方法二:git reset --hard(不推荐)

不推荐理由:git reset将使历史无法恢复。假设有a、b、c三次顺序提交,那么假设被回滚到a,则b、c将不复存在。

git log --oneline 

931568f remove a.md
f622cef add c.md
2a0c5a9 add b.md
6fbba34 add a.md

# 假设我们要恢复到2a0c5a9,则可以

git reset --hard 2a0c5a9

# 此时ls你将看到a.md

git push -f

#这里需要增加-f或者--force命令,原因当前的HEAD指针指向了一个旧版本,而服务器上这个版本不是最新版本。其实服务器并不知道你是使用reset命令得到的旧版本,以为你是一个长期没有获取最新版本的用户,提交了一个错误的版本。因此它会建议你git pull之后再更新。如果你非常明确你要这么做,并且不关心你目标版本之后的版本(可能包含别人的提交),你大可以就此使用-f来强制提交。同时你将获得一个干净的历史,就像什么都没有发生过一样。