Showing posts with label shorthowto. Show all posts
Showing posts with label shorthowto. Show all posts

Sunday, January 11, 2009

Resolve Conflicts in Git

I am going to tell you something very basic here. These basics are really important though.

Today when I tried to merge one of my branch say phuddu to my master, I got some weired messages from git.

...
ERROR: Merge conflict in app/models/activity.rb
Auto-merging app/models/death_report.rb
...
fatal: merge program failed
Automatic merge failed; fix conflicts and then commit the result.

Looks like I crashed into a merge conflict today.

My app/models/activities.rb file looked like following.

<<<<<<< .merge_file_sdfPaP
# == Schema Info
=======
# == Schema Information
>>>>>>> .merge_file_LT3vRO
# Schema version: 20090530092020
#
# Table name: activities
#

<<<<<<< .merge_file_sdfPaP
# id :integer(4) not null, primary key
# item_id :integer(4) not null
# user_id :integer(4) not null
# item_type :string(255) not null, default("")
# created_at :datetime
# updated_at :datetime
#

=======
# id :integer(11) not null, primary key
# user_id :integer(11) not null
# item_id :integer(11) not null
# item_type :string(255) not null
# created_at :datetime # updated_at :datetime
#

>>>>>>> .merge_file_LT3vRO

Every chunk of code above within the
 <<<<<<< 
and
 ======= 
reflects the modifications made by other commiter (Oh! why!! why did you do this?) whereas the code within the
 ======= 
and
 >>>>>>> 
reflects the changes made by me. Now to resolve above conflicts we will edit our files according to the need and do the following.
git update-index <filename>
It actually tells the git that conflicts have been resolved in the files. Now just do a commit and you are done.

Sunday, December 2, 2007

ShortHowTo: Aliasing

This is a ShortHowTo on aliasing commands in gnulinux so lemme get to the point fast.

Every time We write some command on the terminal like poweroff,or mplayer or some other long command, We have to hit a lot of keys. And this really is time consuming. Although auto-completion of commands is really useful but I guess We have to be much more efficient. Well the solution to this problem is aliasing commands.

In gnulinux or other UNIX like environment you have a .bashrc shell script in your home directory. Every time you open a new terminal or new terminal tab this script executes and sets some environment variables for current terminal or terminal tab opened.

Lets alias a command say clear to just c.

1. open the .bashrc file using your favorite text editor.

$vim ~/.bashrc

2.Go to the end of the file and type following line.

alias c=clear

3.save the file.

Now to check if it really worked open a new tab into your termianl and spread some mess on the termianl screen say

$ls
$c


WoW it worked.

aliasing long commands is really very good but the real exploitation of alias is when you use it for most frequently typed commands by you.

Following are the commands which I have aliased. Tell me if also have some more aliases up your sleeve.

alias c=clear
alias l=ls
alias t=touch
alias d=cd
alias v=vim
alias mp=mplayer
alias off=poweroff