您的位置:首页 > 其它

Git Tutorial 3 - Scenario Extension - revert

2015-11-13 17:28 423 查看
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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: