Revert a git commit

Refer: http://christoph.ruegg.name/blog/git-howto-revert-a-commit-already-pushed-to-a-remote-reposit.html

NOTE: This is currently untested, but revert was tested

Case 1: Delete the last commit

Deleting the last commit is the easiest case. Let's say we have a remote mystuff with branch master that currently points to commit dd61ab32. We want to remove the top commit. Translated to git terminology, we want to force the master branch of the mystuff remote repository to the parent of dd61ab32:

$ git push mystuff +dd61ab32^:master

Where git interprets x^ as the parent of x and + as a forced non-fastforward push. If you have the master branch checked out locally, you can also do it in two simpler steps: First reset the branch to the parent of the current commit, then force-push it to the remote.

$ git reset HEAD^ --hard
$ git push mystuff -f

Case 2: Delete the second last commit

Let's say the bad commit dd61ab32 is not the top commit, but a slightly older one, e.g. the second last one. We want to remove it, but keep all commits that followed it. In other words, we want to rewrite the history and force the result back to mystuff/master. The easiest way to rewrite history is to do an interactive rebase down to the parent of the offending commit:

$ git rebase -i dd61ab32^

This will open an editor and show a list of all commits since the commit we want to get rid of:

pick dd61ab32
pick dsadhj278
...

Simply remove the line with the offending commit, likely that will be the first line (vi: delete current line = dd). Save and close the editor (vi: press :wq and return). Resolve any conflicts if there are any, and your local branch should be fixed. Force it to the remote and you're done:

$ git push mystuff -f

Good Old Revert Instead, Create a feature branch to rollback changes, then in LIFO order

$ git revert --no-commit SHA-1(D)
$ git revert --no-commit SHA-1(C)
$ git revert --no-commit SHA-1(B)
$ git revert --no-commit SHA-1(A)
$ git commit -m "rolling back changes"

Live CD Skipping Installation Splash

Refer: http://askubuntu.com/questions/47522/how-to-bypass-try-it-install-screen-when-booting-from-usb-live-session-wit
Release with updates installed:
http://old-releases.ubuntu.com/releases/


$sudo nano /cdrom/syslinux/syslinux.cfg

Replace:

# D-I config version 2.0
include menu.cfg
default vesamenu.c32
prompt 0
timeout 50
ui gfxboot bootlogo

with this for 32-bit:

default live
label live
say Booting an Ubuntu Live session...
kernel /casper/vmlinuz
append file=/cdrom/preseed/ubuntu.seed boot=casper initrd=/casper/initrd.lz quiet splash noprompt --

with this for 64-bit:

default live
label live
say Booting an Ubuntu Live session...
kernel /casper/vmlinuz.efi
append file=/cdrom/preseed/ubuntu.seed boot=casper persistent initrd=/casper/initrd.lz quiet splash noprompt --

Fix right-handle problem with Ubuntu

https://bugs.launchpad.net/ubuntu/+source/metacity/+bug/878198

Another workaround is to hack the theme itself. For the Ambiance theme edit

$sudo gedit /usr/share/themes/Ambiance/metacity-1/metacity-theme-1.xml

and in the section starting
<frame_geometry name="frame_geometry_normal"
change left_width, right_width and bottom_height from 1 to 3.

I have not tried it on the Radiance theme but I expect the same change would work there. Keep a note of what you have done as if the theme is updated you might have to do it again.

What is umask?

Refer: http://www.cyberciti.biz/tips/understanding-linux-unix-umask-value-usage.html

What is Umask and How To Setup Default umask Under Linux?

When user create a file or directory under Linux or UNIX, she create it with a default set of permissions. In most case the system defaults may be open or relaxed for file sharing purpose. For example, if a text file has 666 permissions, it grants read and write permission to everyone. Similarly a directory with 777 permissions, grants read, write, and execute permission to everyone.

Default umask Value

The user file-creation mode mask (umask) is use to determine the file permission for newly created files. It can be used to control the default file permission for new files. It is a four-digit octal number. A umask can be set or expressed using:

  • Symbolic values
  • Octal values

Procedure To Setup Default umask

You can setup umask in /etc/bashrc or /etc/profile file for all users. By default most Linux distro set it to 0022 (022) or 0002 (002). Open /etc/profile or ~/.bashrc file, enter:
# vi /etc/profile
OR
$ vi ~/.bashrc
Append/modify following line to setup a new umask:
umask 022
Save and close the file. Changes will take effect after next login. All UNIX users can override the system umask defaults in their /etc/profile file, ~/.profile (Korn / Bourne shell) ~/.cshrc file (C shells), ~/.bash_profile (Bash shell) or ~/.login file (defines the user's environment at login).

Explain Octal umask Mode 022 And 002

As I said earlier, if the default settings are not changed, files are created with the access mode 666 and directories with 777. In this example:

  1. The default umask 002 used for normal user. With this mask default directory permissions are 775 and default file permissions are 664.
  2. The default umask for the root user is 022 result into default directory permissions are 755 and default file permissions are 644.
  3. For directories, the base permissions are (rwxrwxrwx) 0777 and for files they are 0666 (rw-rw-rw).

In short,

  1. A umask of 022 allows only you to write data, but anyone can read data.
  2. A umask of 077 is good for a completely private system. No other user can read or write your data if umask is set to 077.
  3. A umask of 002 is good when you share data with other users in the same group. Members of your group can create and modify data files; those outside your group can read data file, but cannot modify it. Set your umask to 007 to completely exclude users who are not group members.

But, How Do I Calculate umasks?

The octal umasks are calculated via the bitwise AND of the unary complement of the argument using bitwise NOT. The octal notations are as follows:

        • Octal value : Permission
        • 0 : read, write and execute
        • 1 : read and write
        • 2 : read and execute
        • 3 : read only
        • 4 : write and execute
        • 5 : write only
        • 6 : execute only
        • 7 : no permissions

Now, you can use above table to calculate file permission. For example, if umask is set to 077, the permission can be calculated as follows:

Bit Targeted at File permission
0 Owner read, write and execute
7 Group No permissions
7 Others No permissions

To set the umask 077 type the following command at shell prompt:
$ umask 077
$ mkdir dir1
$ touch file
$ ls -ld dir1 file

Sample outputs:

drwx------ 2 vivek vivek 4096 2011-03-04 02:05 dir1
-rw------- 1 vivek vivek    0 2011-03-04 02:05 file

Task: Calculating The Final Permission For FILES

You can simply subtract the umask from the base permissions to determine the final permission for file as follows:
666 - 022 = 644

  • File base permissions : 666
  • umask value : 022
  • subtract to get permissions of new file (666-022) : 644 (rw-r--r--)

Task: Calculating The Final Permission For DIRECTORIES

You can simply subtract the umask from the base permissions to determine the final permission for directory as follows:
777 - 022 = 755

  • Directory base permissions : 777
  • umask value : 022
  • Subtract to get permissions of new directory (777-022) : 755 (rwxr-xr-x)

How Do I Set umask Using Symbolic Values?

The following symbolic values are used:

  1. r : read
  2. w : write
  3. x : execute
  4. u : User ownership (user who owns the file)
  5. g : group ownership (the permissions granted to other users who are members of the file's group)
  6. o : other ownership (the permissions granted to users that are in neither of the two preceding categories)

The following command will set umask to 077 i.e. a umask set to u=rwx,g=,o= will result in new files having the modes -rw-------, and new directories having the modes drwx------:
$ umask u=rwx,g=,o=
$ mkdir dir2
$ touch file2
$ ls -ld dir2 file2

Sample umask Values and File Creation Permissions

If umask value set to User permission Group permission Others permission
000 all all all
007 all all none
027 all read / execute none

all = read, write and executable file permission

Limitations of the umask

  1. The umask command can restricts permissions.
  2. The umask command cannot grant extra permissions beyond what is specified by the program that creates the file or directory. If you need to make permission changes to existing file use the chmod command.

umask and level of security

The umask command be used for setting different security levels as follows:

umask value Security level Effective permission (directory)
022 Permissive 755
026 Moderate 751
027 Moderate 750
077 Severe 700

For more information about the umask read the man page of bash or ksh or tcsh shell:
man bash
help umask
man chmod

Ramdisk

Possible solution for faster access:
http://www.pcworld.com/article/260918/how_to_supercharge_your_pc_with_a_ram_disk.html

 

Unix Nohup: Run a Command or Shell-Script Even after You Logout

When you execute a Unix job in the background ( using &, bg command), and logout from the session, your process will get killed. You can avoid this using several methods — executing the job with nohup, or making it as batch job using at, batch or cron command. This quick tip is for beginners. If you’ve been using nohup for a while, leave us a comment and tell us under what situations you use nohup. In this quick tip, let us review how to make your process running even after you logout, using nohup. Nohup stands for no hang up, which can be executed as shown below.

nohup syntax: $nohup command-with-options &

Git with Rebase

You can use rebase to merge and get around conflicts in Git.  Here's an  that points out the issues with thie, meaning it's not a magic bullet.