GIT: How to use stash

- by admin

Git features The Stash, which is as much as a good place to store uncommitted changes. When you stash you changes, the will be stored, and your working copy will be reverted to HEAD (the last commit revision) of your code.

When you restore your stash, you changes are reapplied and you continue working on your code.

Stash your current changes
$ git stash save 
Saved "WIP on master: f12345..."

List current stashes

Yes, you can have more than one!! The stash works like a stack. Every time you save a new stash, it's put on top of the stack.
$ git stash list
stash@{0}: WIP on master: f12345..."

Note the stash@{0} part? That's your stash ID, you'll need it to restore it later on. Let's do that now. The stash ID changes with every stash you make. stash@{0} refers to the last stash you made.

Apply a stash
$ git stash apply stash@{0}

You may notice the stash is still there after you have applied it. You can drop it if you don't need it any more.
$ git stash drop stash@{0}

Or, because the stash acts like a stack, you can pop off the last stash you saved:
$ git stash pop

If you want to wipe all your stashes away, run the 'clear' command:
$ git stash clear

It may very well be that you don't use stashes that often. If you just want to quickly stash your changes to restore them later, you can leave out the stash ID.
$ git stash
...
$ git stash pop

IBM ThinkVantage System Update Failure

- by admin

Error:

I have got "Unable to connect to proxy server" error while running IBM Think Vantage System Update. OS is Windows 7.

Fix:

Internet Explorer: Tools => Internet Options => Connections => Lan Settings: uncheck "Use a Proxy Server" and "Use automatic configuration script"

Git Cheat Sheet

- by admin

Configuration


identify yourself to git: email and your name

git config --global user.name "John Smith"

git config --global user.email "abc@mail.com"

To view all options:

git config --list

OR

cat .git/config

Set up aliases


git config --global alias.co checkout

View your configuration


cat .gitconfig

To ignore whitespace (Ruby is whitespace insensitive)


git config --global apply.whitespace nowarn

Some nice aliases:

gb = git branch
gba = git branch -a
gc = git commit -v
gd = git diff | mate
gl = git pull
gp = git push
gst = git status

Start using git


git init

Ignoring files


Add a file in the root directory called .gitignore and add some files to it: (comments begin with hash)

*.log db/schema.rb db/schema.sql

Git automatically ignores empty directories. If you want to have a log/ directory, but want to ignore all the files in it, add the following lines to the root .gitignore: (lines beginning with ‘!’ are exceptions)

log/*
!.gitignore

Then add an empty .gitignore in the empty directory:

touch log/.gitignore

Scheduling the addition of all files to the next commit


git add .

Checking the status of your repository


git status

Committing files


git commit -m "First import"

Seeing what files have been committed


git ls-files

Scheduling deletion of a file


git rm [file name]

Committing all changes in a repository


git commit -a

Scheduling the addition of an individual file to the next commit


git add [file name]

Viewing the difference as you commit


git commit -v

Commit and type the message on the command line


git commit -m "This is the message describing the commit"

Commit and automatically get any other changes


git commit -a

A “normal” commit command


git commit -a -v

Viewing a log of your commits


git log

Viewing a log of your commits with a graph to show the changes


git log --stat

Viewing a log with pagination


git log -v

Visualizing git changes


gitk --all

Creating a new tag and pushing it to the remote branch


git tag "v1.3"
git push --tags

Creating a new branch


git branch [name of your new branch]

Pushing the branch to a remote repository


git push origin [new-remote]

Pulling a new branch from a remote repository


git fetch origin [remote-branch]:[new-local-branch]

Viewing branches


git branch

Viewing a list of all existing branches


git branch -a

Switching to another branch


The state of your file system will change after executing this command.

git checkout [name of the branch you want to switch to]

OR

git co [name of the branch you want to switch to]

Making sure changes on master appear in your branch


git rebase master

Merging a branch back into the master branch


First, switch back to the master branch:

git co master

Check to see what changes you’re about to merge together, compare the two branches:

git diff master xyz

If you’re in a branch that’s not the xyz branch and want to merge the xyz branch into it:

git merge xyz

Reverting changes to before said merge


git reset --hard ORIG_HEAD

Resolving conflicts


Remove the markings, add the file, then commit.

Creating a branch (and switching to the new branch) in one line


git checkout -b [name of new branch]

Creating a stash (like a clipboard) of changes to allow you to switch branches without committing


git stash save "Put a message here to remind you of what you're saving to the clipboard"

Switching from the current branch to another


git co [branch you want to switch to]

Do whatever
Then switch back to the stashed branch

git co [the stashed branch]

Viewing a list of stashes


git stash list

Loading back the stash


git stash apply

Now you can continue to work where you were previously.

Deleting a branch (that has been merged back at some point)


git branch -d [name of branch you want to delete]

Deleting an unmerged branch


git branch -D [name of branch you want to delete]

Deleting a stash


git stash clear

Setting up a repository for use on a remote server


Copy up your repository. e.g.:

scp -r my_project deploy@yourbox.com:my_project

Move your files on the remote server to /var/git/my_project
For security make the owner of this project git
On the repository server:

sudo chown -R git:git my_project

Then (for security) restrict the “deploy” user to doing git-related things in /etc/passwd with a git-shell.

Checking out a git repository from a remote to your local storage


git clone git@yourbox.com:/var/git/my_project

Viewing extra info about a remote repository


cat .git/config

By virtue of having cloned the remote repository, your local repository becomes the slave and will track and synchronize with the remote master branch.

Updating a local branch from the remote server


git pull

Downloading a copy of an entire repository (e.g. laptop) without merging into your local branch


git fetch laptop

Merging two local branches (ie. your local xyz branch with your local master branch)USE MERGE


git merge laptop/xyz

This merged the (already copied laptop repository’s xyz branch) with the current branch you’re sitting in.

Viewing metadata about a remote repository


git remote show laptop

Pushing a committed local change from one local branch to another remote branch


git push laptop xyz

Creating a tracking branch (i.e. to link a local branch to a remote branch)


git branch --track local_branch remote_branch

You do not need to specify the local branch if you are already sitting in it.

git pull

Note: You can track(link) different local branches to different remote machines. For example, you can track your friend’s “upgrade” branch with your “bobs_upgrade” branch, and simultaneously you can track the origin’s “master” branch (of your main webserver) with your local “master” branch.

By convention, ‘origin’ is the local name given to the remote centralized server which is the waySVN is usually set up on a remote server.

Seeing which local branches are tracking a remote branch


git remote show origin

Working with a remote Subversion repository (but with git locally)


git-svn clone [http location of an svn repository]

Now you can work with the checked out directory as though it was a git repository. (cuz it is)

Pushing (committing) changes to a remote Subversion repository


git-svn dcommit

Updating a local git repository from a remote Subversion repository


git-svn rebase

NOTE: make sure you have your perl bindings to your local svn installation.

I screwed up, how do I reset my checkout?


git checkout -f

How to copy / paste text in gitk

- by admin

Problem:

How to copy / paste text from git?

Text select and Ctrl-C + Ctrl-V does not paste the copied text. And there is no Edit / Copy / Paste menu item.

Solution:

gitk supports the normal X clipboard, thus

  1. 1. Select text, Ctrl-C to copy.

  2. 2. Paste text into X terminal window used to start gitk ! It does paste here.

  3. 3. Next do copy / paste again to any of your editor / tool.


Voila !

Center Multiple DIVs with CSS

- by admin

At some point, you may have a situation where you want to center multiple elements (maybe <div> elements, or other block elements) on a single line in a fixed-width area. Centering a single element in a fixed area is easy. Just add margin: auto and a fixed width to the element you want to center, and the margins will force the element to center.

There really should be a similar simple way to center multiple elements evenly spaced. It would be nice if CSS had a property called “box-align” which you could set to “center” then the child elements would be centered evenly within their parent.

Well, you can achieve something similar by taking advantage of CSS’s flexibity with “recasting” elements (for lack of a better term). View a demo of what I’ll be describing in this short tutorial.

The Usual Way


Normally, in such a situation, you would just float the boxes, then add left and right margins to space them out accordingly. But that can get a little messy, because IE6 doesn’t like margins on floats, and you always have to have a different id or class for elements on which you don’t want margins (like the last and/or the first).

You can get around the IE6 problem by adding display: inline in an IE6-only declaration, but your code will still be somewhat messy because of the extra code to get the first and/or last item to behave. Also, the last box could fall to the next line in IE.

There’s another solution to this that might work better in certain circumstances.

Use inline-block and control white space


To achieve the same effect as adding floats and margins, you can simply “recast” your block-level elements as inline blocks, and then manipulate the white space between them. Here is how the CSS might look:
#parent {
    width: 615px;
    border: solid 1px #aaa;
    text-align: center;
    font-size: 20px;
    letter-spacing: 35px;
    white-space: nowrap;
    line-height: 12px;
    overflow: hidden;
}
.child {
    width: 100px;
    height: 100px;
    border: solid 1px #ccc;
    display: inline-block;
    vertical-align: middle;
}

In my example above, I’m assuming there are four child boxes, each with the class child, and each 100 pixels by 100 pixels. The boxes are naturally block-level elements, but the CSS changes them to inline-block, which allows them to flow naturally with text and white space. Of course, since we don’t have any text in the parent container, controlling the text and white space will not be a problem.

The parent element (with the id parent in this example) has four key text properties set, and the children have two:

  • text-align makes all inline child elements centered

  • letter-spacing controls the size of each white space unit between boxes

  • white-space: nowrap keeps the last element from potentially dropping to the next line

  • overflow: hidden prevents the box from stretching in IE6

  • vertical-align: middle (on the children) keeps the boxes on the same vertical plane as each other when content is added

  • display: inline-block (obviously)


Internet Explorer Rears its Ugly Head


What would a CSS solution be without an Internet Explorer issue to work around? While this method works exactly the same in every browser (including IE8), IE6 and IE7 don’t cooperate, because they don’t fully support inline-block. To get those browsers to show virtually the same result, you need to add the following CSS:
.child {
    *display: inline;
    *margin: 0 20px 0 20px;
}

The CSS above must apply only to IE6 and IE7, and it has to appear after the other CSS. In my code (and in the code example above) I’ve accomplished this by using the star hack. The asterisk (or star) at the beginning of each line hides both lines from every browser except IE6 and IE7. The margins added here help us get the same visual result, and the new display property is taking advantage of a bug in those browsers that makes a block element work like its inline when you declare display: inline-block followed by display: inline.

Drawbacks / Final Thoughts


Not many drawbacks to this. You just have to make sure the white space and text settings that you apply are reset on any child elements inside the boxes. So, while this may work when you have straight images or other non-text content, it may be more trouble than its worth if your boxes are fully loaded with diverse content.

But nonetheless a good technique to know when you have to center some block elements with equal spacing, and you don’t want to apply extra classes on the end units. And this technique will be even more important when the older versions of IE disappear from general use.

Git: Push and Delete Remote Branches

- by admin

You can push the branch up to a remote very simply:
git push origin newfeature

Where origin is your remote name and newfeature is the name of the branch you want to push up.

Deleting is also a pretty simple task:
git push origin :newfeature

That will delete the newfeature branch on the origin remote, but you’ll still need to delete the branch locally with git branch -d newfeature.

Mac X11 window font size change

- by admin

The most simple way is adding the following new command in the X11-> application -> customize:
xterm -geometry 72x34+100+40 -fn *-fixed-*-*-*-20-* &

Mac OS X Lion: configure: error: C compiler cannot create executables

- by admin

After Xcode installation and trying to build mc I've got:
configure: error: C compiler cannot create executables

Google offers to install Xcode correctly (this is a different story however) or to reinstall it. Hmmm. Good idea but in my case the following simple action solved the issue: symlinks for compilers - that's all ! KISS
sudo ln -s /usr/bin/llvm-gcc-4.2 /usr/bin/gcc-4.2

sudo ln -s /usr/bin/llvm-g++-4.2 /usr/bin/g++-4.2

Voila !

Uncaught exception 'Zend_Mail_Transport_Exception' with message 'Unable

- by admin

Error:

Fatal error: Uncaught exception 'Zend_Mail_Transport_Exception' with message 'Unable to send mail. ' in /.........../Zend/Zend/Mail/Transport/Sendmail.php:137

Postfix is running, PHP can connect to Postfix.

We have got In Apache error_log:
postdrop: warning: uid=48: File too large

FIX:

The default max message size for Postfix is 10240000 bytes. Thus we do:
% /usr/sbin/postconf -e message_size_limit=XXXXXXXXXXX

where XXXXXXXXXX is the new limit.

And then restart Postfix.

FYI: Related issues:

The the default value for a mailbox size according to Postfix is 51200000 bytes. It may be changed like this:
% postconf -e mailbox_size_limit=0

And then restart Postfix.

The settings for all the size related parameters (in main.cf) can be listed like this:
# postconf -d | grep size

Sample output:
berkeley_db_create_buffer_size = 16777216
berkeley_db_read_buffer_size = 131072
body_checks_size_limit = 51200
bounce_size_limit = 50000
header_size_limit = 102400
mailbox_size_limit = 51200000
message_size_limit = 10240000

Voila !

Mac OS X - MySQL Workbench - Error Opening Configuration File my.cnf

- by admin

By default, the OS X installation does not use a my.cnf, and MySQL just uses the default values.

To set up your own my.cnf, you could just create a file straight in /etc, or do the following (excuse me if I say anything which is obvious to you, but this may help complete OS X beginners who are not familiar with the Unix command line):

Log in to OS X using an administrator-level account (to keep things simple lower down)

Open Terminal (in Utilities folder under Applications folder)
cd /usr/local/mysql/support-files/
sudo cp my-huge.cnf /etc/my.cnf

and enter your admin password when prompted. You could do this from a non-admin account by using the su command, but that's probably a bit scary for some people ;)

You will now have a copy of my.cnf in /etc (just in case you don't know, that means the etc folder directly under the root folder, not under MySQL's install folder)

You can edit it with a text-editor such as TextWrangler by using File->Open Hidden, or if you are happy to use the command line, use:
cd /etc
sudo nano my.cnf

To exit without saving, press CTRL+X, to Save then exit it's: CTRL+O then CTRL+X

« Newer posts

Older posts »