Tuesday, January 24, 2012

Git: Restore files deleted in older commits

Git is a Distributed Revision Control System. These four words seem familiar, but provide a powerful mechanism when all of them come together and Git is its resultant.

However well an application may be documented, it does not satisfy all the queries.

One such query I came across in my work was "How to retrieve the files those were deleted in older commits and not just the latest commit"

Below are the two ways to do that. First is the one what I prefer and the second one is recommended by a friend.

Consider, 3 commits have been made

Commit 1 : Initial Commit, Commit A. Files to be restored reside in this commit.
Commit 2 : deleted files say, A.txt and B.txt which has been committed as Commit B
Commit 3 : Made few Changes and committed as Commit C and many commits done so on.

Problem: Retrieve files A.txt and B.txt to current Head.

Solution:

First Method:

  1. List all the files those were deleted irrespective of the commits in which they were made.
$ git log --diff-filter=D --summary

          results as follows: SHA-1 of commit in which the delete of files A.txt and B.txt was committed, commit message, deleted files etc.



      2.     Find the SHA-1 of commit which last contained the files i.e. Commit just previous to the one listed in Step 1.


            Use $ git log command. In our eg, the log for 3 commits with their respective SHA-1's look as follows:




In our example, the commit which contains our files is 1bf2d..., say source to retrieve files from.


      3.  Restore the files

Use $ git checkout <revision> file.ext
  • revision : SHA-1 of source commit
  • file.ext : file name and path from where to retrieve.(Files are retrieved to their older path and not to new place. Of course, you can move them through Cut-Paste once restore.)


       4.  Do not forget to commit once the files are restored. In our eg after commit, the directory listing shows that the files are restored. The above snap shows that listing and deleted files A.txt and B.txt are restored back to same location.

Second Method:
  1. Use $ git log know the SHA1 commit versions.
  2. Check out the commit which contains the files you want to retrieve. Now, you will find the deleted files in the directory. Copy them to a temporary location.
  3. Now, again checkout to the latest commit i.e. Get back to the same place where you were before Step 2.
  4. Add the files to their respective directories from the temporary location.
  5. And, finally commit and list the directory to find the files.
Which method is better?

Both methods have upper hand depending on the situation and requirements.
  • If you want to restore the files to some new locations other than from where they were originally deleted, second method is good. However, you can use first method and then change file locations.
  • If you want the files to restore to same locations, first method is good. Ofcourse, with second method also you can do it. But, the overhead of copying files to temporary locations is eliminated in first method.
  • I would recommend the first method because the checking out to previous without committing the current may result in loosing your work yet to be committed for current verison.
Hope, this article has helped you and served the purpose for which you have visited this page.

Do post your feedbacks. Thats encouraging.

Monday, January 23, 2012

ICS vs iOS 5.0



7 days after Apple released it’s highly anticipated iOS 5 on October 12, 2011, Google announced it’s another sweet treat by name Ice Cream Sandwich, the first unified version of OS for tablets and smart phones, in succession to Gingerbread and Honeycomb on October 19, 2011.

Now, as both are launched and a significant time has passed to experience their features, the question arises as to which is the best.

The major issue comes that where they can work on. While iOS works only on Apple products, which is not the case with Ice Cream Sandwich.  Ice Cream Sandwich’s operating system is an open source OS, and it can easily run on any third party phones and tablets.

User Interface: 

To start with user interface, iOS aims at simplicity and any naïve user can grab an iOS 5 based Apple products and get going.  For Android, its quite opposite.  For someone who already knows their way around, it’s simple. But when you start, you might have to go through a couple of extra menus to get to the thing you need, however, it’s a lot more flexible than the iOS.


Voice Assistant:

Apple released its voice assistant service, siri, which is a really creative thing that provides users a totally different experience, and become the focus of the smartphone field. However, after the first few month’s fresh, I don’t think people will speak to their smart phone on the street.

Voice assistant appeared on Android system long before. But due to the limitation on content, voice assistant on Android is far behind iPhone 4s’s Siri. Even though Android’s voice assistant also has a nice performance. It can help you to make a call, send SMS, open GPS, play music and take a note and so on.

Gaming:

When it comes to games, iOS 5 gives a better experience than ICS. This is not only because iOS has its own Game Center, but also because the hardware of the devices. For example, the new iPhone 4s has dual-core Graphics processor, while in Android phones; only Samsung Galaxy nexus is comparable. In Android 4.0, we only find the new 3D driver

Browser:

 Both ICS and iOS 5 have beefed up there browser capabilities in own respect. ICS uses chrome based browser and iOS uses Safari. ICS chrome has got features like Google chrome bookmarks sync, incognito window and also a useful feature of offline web page caching for offline reading. Apple has got Reading Lists that allow you to save web pages to read later but however it does not support offline caching of web pages as does ICS. But an interesting thing Reading Lists does is it syncs across all your iCloud enabled devices. iOS 5 added tabbed browsing which was added to Android tablets since Gingerbread.

Near Field Communication:

Android Beam takes the notion of NFC even further by allowing data transfer between compatible devices just by tapping their backs and ofcourse for the mobile payments. However, iOS 5 did not include any NFC technology.  Several analysts said Apple won't be hurt by waiting to deliver an NFC-ready iPhone.

Customization:

 For the customization part, iOS really isn't customization without a jailbreak. Without a iailbreak, you will only be able to rename folders and change wallpapers, that's all. But when it comes to jailbreak, you can do several things like apply different themes, customize your lock screen, change names of Applicationsand much more. But with Android, you can do everything without doing anything at all. However, jailbreaking or rooting on Android is far more complex than on iOS Devices.

Facial login:

Apple still remains true to its good old 'swipe to unlock' screen gesture, while Android steps ahead with their new facial login capability. While Apple fans still swipe across that dainty touchscreen, Android users can flash those pearly whites to make their way across a locked screen.  Android really puts you 'into the picture'.

For me:



Hope this picture says what I want to.
Stay tuned. More to come...