Git Tutorial 3 - Scenario Extension - revert

來源:互聯網
上載者:User

標籤:

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 loggit ls-tree HEADls -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.

Git Tutorial 3 - Scenario Extension - revert

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.