This are my notes in the fields of computer science and technology. Everything is written with ABSOLUTE NO WARRANTY of fitness for any purpose. Of course, feel free to comment anything.

Tuesday, August 11, 2009

git: write a single commit to file

Write the commit to file:
git diff-tree <commit> -p --pretty > <filename>
You can also use git format-patch, but that is more specialized for patches to be submitted by email.

Apply the commit from the file:
git apply <filename>
Here is an excerpt from the git diff-tree manual page:
When "git-diff-index", "git-diff-tree", or "git-diff-files"
are run with a -p option, "git diff" without the --raw option,
or "git log" with the "-p" option, they do not produce the output
described above; instead they produce a patch file. You can
customize the creation of such patches via the GIT_EXTERNAL_DIFF
and the GIT_DIFF_OPTS environment variables

Monday, August 10, 2009

Scite: add a vertical line at column 80

A tip for the SciTE editor: this is interesting if you want your code to be easy to print and display without horizontal scrolling.

Add the following to the global or user properties file:
edge.column=80
edge.mode=1
edge.colour=#C0DCC0
This is an excerpt of the SciTE documentation for the edge property:
Indicates long lines. The default edge.mode, 0, does not
indicate long lines. An edge.mode of 1 uses a vertical
line to indicate the specified column and an edge.mode
of 2 changes the background colour of characters beyond
that column. For proportional fonts, an edge.mode of 2
is more useful than 1.

Sunday, August 9, 2009

Compact guide to less commands

Movement

Arrows, page up/down, home/end keys all work as expected. In addition the following are sometimes useful:
d/uMove half page forward / backward
20gMove to line 20
20%Move to the 20% point
ma/'aset markpoint "a" / move to markpoint "a"
(also instead of "a" any other lowcase letter)

Search

/patternsearch pattern forward
?patternsearch pattern backward
nnext match
Nprevious match
/!patternsearch non-matching line
Esc-uturn match highlighting on/off

Misc

=show info about the file and current position
! commandexecute command and show its output
s filenamesave to file (if the input was a pipe)

GIT_PAGER and LESS colors

I was wondering why, working on two different machines, I was able to display git-log and git-diff colors on one machine and not on the other, despite the same git configuration file ~/.gitconfig:

[color]
diff = auto
status = auto
branch = auto
log = auto

and no particular settings regarding colors in <repository>/.git/config

Although I was not using a Mac, the solution was in this blog post: that is, setting the GIT_PAGER variable to cat was already solving the problem; GIT_PAGER sets which program should be used by git to display for example the diff and log output (default less).

The actual problem was in less and how it outputs ANSI color ESC codes. A solution, similarly to what suggested in that post, was to set the LESS variable to -R and leave GIT_PAGER unset, as it originally was. Regarding the other options suggested in the blog post for LESS, -X and -e have no influence on color display, and -R is probably better than -r; in particular, this in an extract of the less manual, at the -r/-R section, explaining why:
-r or --raw-control-chars

Causes "raw" control characters to be displayed.
[...] Warning: when the -r option is used, less cannot
keep track of the actual appearance of the screen
(since this depends on how the screen responds to
each type of control character). Thus, various display
problems may result, such as long lines being split
in the wrong place.

-R or --RAW-CONTROL-CHARS

Like -r, but only ANSI "color" escape sequences are
output in "raw" form. Unlike -r, the screen appearance
is maintained correctly in most cases. [...]

About Me

My photo
Hamburg, Hamburg, Germany
Former molecular biologist and web developer (Rails) and currently research scientist in bioinformatics.