Git Tutorial 3 - Scenario Extension - revert

Git tutorial previously, I have committed the 3 files to local repository. Then suddently I was aware of the file list.png was committed by mistake. It would‘ve been left behind and been clean from my working directory after I get other files in local repo rather than let it in. So I used git rm and git commit to correct my fault. At the end I showed the git log to explain that the list.png was removed from current snapshot in local repo but in a prevous snapshot it‘s still here.

Don‘t worry about that your boss or buddies one day track the history of git log to realize that mistake and correction you‘ve ever made. Always remember that it‘s worth preserving history. Sometimes you can be blamed by history, sometimes you can be saved by history. Embarrassing cannot make you get shit, being saved could be really a big deal.

For whatever reason, my boss gives me an order that all files I‘ve removed must come back immediately after somedays I commit the deletion for it. Let‘s see what can I do to rescue this fxxking situation. Take a look at below git log message and working directory to see what we get

git log
git ls-tree HEAD
ls -l

figure 3.1

list.png is nether in the latest snapshot (see the command checked by git ls-tree) nor in working directory. Now we‘re going to use commad git revert to rollback the commitment of deletion with the commit ID in red rectangle.

git revert 2ee281b4

figure 3.2

You don‘t need to type the full of commit ID, just the part at the start could be OK.

And then take a look at the local repository and working directory to see if list.png‘s come back.

figure 3.3

Seeee, it does work! Don‘t hurry up to report your boss with the finish. Let me use git log to have a look what happened just then

figure 3.4

Instead of removing the commit from the history, Git figured out how to undo the changes introduced by the specified commit ID (it‘s 2ee281b4 here) and appended a new commit with the resulting content.

时间: 2024-08-05 07:08:45

Git Tutorial 3 - Scenario Extension - revert的相关文章

Git Tutorial 5 - Branch and Merge

Branch is a very important concept in Git and doing branch is one of the greatest features. It plays like the concept of context when you're working on it. You can have multiple branches in your repo, and in a time you're working in only one of them.

Git Tutorial 2 - Goto Local Repository

In last episode I have added 3 files to Staging area and also explain how to undo your operation. At next I'm going to show you how to commit the 3 files from staging area to local repository. Git provides developers a private copy of the whole repos

Git Tutorial 1 - Goto Staging area

This tutorial is actually for myself as some memos. It provides some example and explanation for the most important commands which might be simple but is worth noting down for your long term memory. I am not going to write tons of commands and their

Git Tutorial 7 - File States

File States Overview Every file in your working directory is mainly in one of 2 states: 1. Tracked : All files that were committed to the last snapshot in Git repository are in state Tracked. They can be one of the following states: 1.1 Unmodified : 

代码回滚:git reset、git checkout和git revert区别和联系

git reset.git checkout和git revert是你的Git工具箱中最有用的一些命令.它们都用来撤销代码仓库中的某些更改,而前两个命令不仅可以作用于提交,还可以作用于特定文件. 因为它们非常相似,所以我们经常会搞混,不知道什么场景下该用哪个命令.在这篇文章中,我们会比较git reset.git checkout和git revert最常见的用法.希望你在看完后能游刃有余地使用这些命令来管理你的仓库. Git仓库有三个主要组成——工作目录,缓存区和提交历史.这张图有助于理解每个

Git reset head revert 回滚

Overview 涉及Git一些日常操作 :) 基础知识 <Pro Git>至少了解branch,commit的概念,及基本的原理 Git常用魔法 存档:master代码回滚方法 我是QA,我用Git Git 工作区.暂存区和版本库 Overview 暂存区(stage, index)是 Git 最重要的概念之一 工作区: 你的目录下面的文件们 暂存区: 由.git/index保存引用,.git/object保存对象的区域 版本库: 仓库 Relations Why stage before

git代码回滚:Reset、Checkout、Revert的选择

代码回滚:Reset.Checkout.Revert的选择 Zhongyi Tong edited this page on Dec 8, 2015 · 5 revisions Pages 19 Home 2.1 快速指南 2.2 创建代码仓库 2.3 保存你的更改 2.4 检查仓库状态 2.5 检出之前的提交 2.6 回滚错误的修改 2.7 重写项目历史 3.2 保持同步 3.3 创建Pull Request 3.4 使用分支 3.5 常见工作流比较 4.1 图解Git命令 5.1 代码合并:

[Git] git revert ( revert commit 和 revert merge)

转载自:http://blog.csdn.net/qinjienj/article/details/7621887 我们难免会因为种种原因执行一些错误的commit / push,git提供了revert命令帮助程序员修复这样的错误. 举个例子,下图是git commit 的历史记录 git revert 命令会通过一个新的commit 来使仓库倒退一个commit,在上例中,如果程序员想要revert 最新的那次commit (Updated to Rails 2.3.2 and edge h

How To Use Git Source Control with Xcode in iOS 7

Note from Ray: Tutorial Team member Felipe Laso Marsetti has ported this tutorial to iOS 7 as part of the iOS 7 feast. We hope you enjoy! Whether you're a solo developer or working on a team, if you're not using source control for your projects, you