[git] Reverting an accidental commit/amend using reset

Alright. So this one might sound a special case, but there are chances that something like this scenario might turn up too, while playing with git.

Scenario:

You are working on top of a commit de7504f : My original commit, made some changes, and you really wanted to make it into a new commit, but accidently you gave git commit --amend and you are now in the edit commit message of de7504f.

Once saved, you can see in git log that you are in a new commit-id: 7645040: My original commit and amended change.

This can be equivalent to typing git commit, typing in the commit message, saving it – and later thinking – “God, I shouldn’t’ve committed it”.

Solution:

The idea is to run git reset and it would just take you back to a point where you have the changes staged, but not committed yet. To be more human, this is the place after you have made your changes, and typed in git add too.

You can get the commit-id straight from git log, but for my above scenario, since it was an amend, it might not just work. For that, we got git reflog

git reflog

it would list out commit id of every single change you did including amend, rebase, chgeckout, reset etc.

7645040 HEAD@{0}: commit (amend): My original commit and amended change
de7504f HEAD@{1}: commit: My original commit

Yay! Now you need to just run

git reset 7645040 
git status

and you are back in history where you have git add -ed the files, but not done git commit --amend yet. You can add those to a separate commit, or stash it or do whatever.

If you pass git reset 7645040 --hard, all changes which you did after 7645040 would be just thrown off, so use it with caution.

References: https://git-scm.com/docs/git-reset

Advertisements

Boot your (bootable) USB directly from grub

Long time, and I hit across this one scenario, and yay – we have this blog post here!

Scenario
Pretty old machine with a Linux installed, and working grub, and I wanted to install another Linux variant! I got my bootable USB drive ready, but the stupid machine was not detecting it during boot-time I guess, as it never had mind to boot from it.

Similar situation can come up when you forgot the BIOS password, making it difficult for you to change the boot order. So here you go!

Steps
Let me put in steps, so that easy for someone (or even myself) to copy later!

  1. Insert your USB drive, boot normally, go to Grub command line – This might be probably a click of ‘c’ from the Grub menu! You will be in somewhere like
    grub>
    
  2. Type in ls and find out the correct USB drive notation and partition. In my case, it was (hd1, msdos1) You can simply find the correct one by typing in ls (hdx,msdosy)/ or similar
  3. Now we have the partition, lets try booting from it! This is the tricky step, and here you go!
    set root=(hd1,msdos1)
    linux /casper/vmlinuz.efi boot=casper noprompt noeject root=/dev/sdb1
    initrd /casper/initrd.lz
    boot
    
  4. TADA! Here you go! If you see a prompt like
    (initramfs)
    

    You have done something seriously wrong 🙂 Take time to go all the way from top till down again, and if it still dont work out, kindly comment!

Hosting a phabricator install in OpenShift [0/7]

Few days ago, I could finish with a fully functional Phabricator install in OpenShift hosting by Red-Hat. OpenShift[openshift.redhat.com] is a free hosting provider nurtured by Redhat. The hosting service allows you to:

  1. Host atmost 3 small-scale apps for free
  2. Use your own custom domain for the app, like http://phab.amritafoss.in

I will be writing on how to get your Phabrcator installation up and running in the coming blog posts, and the outline of the whole process would be:

  1. Creating your openshift account, and a new web-app with ‘PHP’ catridge
  2. Installing Phabricator in there following https://secure.phabricator.com/book/phabricator/article/installation_guide/
  3. Configuring Phabricator to use the openshift configurations
  4. Writing the .htaccess file to finish things
  5. Setting up Mailgun API to handle mails
  6. Adjusting CNAME records in your domain name provider to redirect correctly
  7. Wrapping up 🙂

Stay Tuned!

Sharing your Linux folders with Android over FTP [ Samba + ES Explorer ] [2/2]

You would’ve got how to start files sharing samba service running in your linux machine in the previous post ( If you haven’t yet [part1] ). Now lets go to the fun part – accessing the file system from your Android phone.

Problem:
You need to access the samba shared files in /media/sam/mypics from your Android phone.
Requirements:

  1. Android phone with ES-Explorer or similar app installed
  2. Your linux machine having samba service running

Approach:
The approach is still the same:
Install FTP server and samba file share in your linux machine with login. Access it via your ES Explorer in Android phone
Steps

  1. Setup a WiFi hotspot in your Android phone, and connect your laptop with itmakingHotspot
  2. Obtain the IP address of your Linux machine by sudo ifconfig
  3. Open ES-Explorer in your Android phone, and go to LAN -> Add new as per the figureunnamed
  4. Give the IP address of the Linux machine you got, and the username and password as what you gave while setting up Samba ( ref: [part1] ).addingFTP
  5. Next time, you can see that your FTP server automatically shows up !
    listingConnected
  6. Enjoy 🙂