Graeme's Wiki

git tips

Type the code word, MONDAY here and then press to finish editing.



Why choose Git?

The URL listed here sums it up perfectly. So instead of me duplicating everything, I will simply link to that website: whyGITisBetterThank

Creating and emailing a patch

If simply want to fix something small and email a patch to a mailing list on NNTP server, you can do the following:
$ git clone git://fpgui.git.sourceforge.net/gitroot/fpgui
$ cd fpgui
$ (edit files)
$ git add (files)
$ git commit -m 'Explain what I changed'
$ git format-patch origin/master

Dealing with newline characters

http://github.com/guides/dealing-with-ne...nes-in-git

Multiple branches using git-svn

This is my preferred choice of doing things...
http://www.jukie.net/~bart/blog/svn-bran...hes-in-git

Here is an alternative method...
http://www.dmo.ca/blog/20070608113513/


How to use the subtree merge strategy


There are situations where you want to include contents in your project from an independently developed project. You can just pull from the other project as long as there are no conflicting paths.

The problematic case is when there are conflicting files. Potential candidates are Makefiles and other standard filenames. You could merge these files but probably you do not want to. A better solution for this problem can be to merge the project as its own subdirectory. This is not supported by the recursive merge strategy, so just pulling won't work.

What you want is the subtree merge strategy, which helps you in such a situation.

In this example, let's say you have the repository at /path/to/B (but it can be an URL as well, if you want). You want to merge the master branch of that repository to the dir-B subdirectory in your current branch.

Here is the command sequence you need:
$ git remote add -f Bproject /path/to/B (1)
$ git merge -s ours --no-commit Bproject/master (2)
$ git read-tree --prefix=dir-B/ -u Bproject/master (3)
$ git commit -m "Merge B project as our subdirectory" (4)

$ git pull -s subtree Bproject master (5)

1. name the other project "Bproject", and fetch.
2. prepare for the later step to record the result as a merge.
3. read "master" branch of Bproject to the subdirectory "dir-B".
4. record the merge result.
5. maintain the result with subsequent merges using "subtree"

The first four commands are used for the initial merge, while the last one is to merge updates from B project.

Git send-email fails under Ubuntu

If you get an error like "Can't locate Net/SMTP/SSL.pm" then it means that a perl module is not installed.
 $ sudo apt-get install libnet-smtp-ssl-perl
The above command should solve the problem and pull in the following packages.

Installed the following packages:
libio-socket-ssl-perl (1.18-1)
libnet-libidn-perl (0.07-1build1)
libnet-smtp-ssl-perl (1.01-2)
libnet-ssleay-perl (1.35-2ubuntu1)

self compiled: git-svn doesn't work

This command will install all required packages to get 'git svn' to work.
$ sudo apt-get install libsvn-perl

Git branch information inside your Bash prompt

You can add the following to your ~/.bashrc file to color-code your git branch into your prompt. So now you can see at a glance not only which branch you're on, but also what type status state you're in!

I've set things up so that a clean git working directory has normal text; untracked files make things red; changed but not updated files make things yellow; and when everything is ready to be committed, things are green.

txtred='\033[0;31m'
txtgrn='\033[0;32m'
txtylw='\033[1;33m'
end='\033[0m'

function parse_git {
branch=$(__git_ps1 "%s")
if [[ -z $branch ]]; then
return
fi

status="$(git status 2>/dev/null)"

if [[ $status =~ "Untracked files" ]]; then
branch=${txtred}${branch}${end}
fi
if [[ $status =~ "Changed but not updated" ]]; then
branch=${txtylw}${branch}${end}
fi
if [[ $status =~ "Changes to be committed" ]]; then
branch=${txtgrn}${branch}${end}
fi

echo -e " ($branch)"
} 

Or if you want a more simplified one and with not color codes:

PS1="[\W\$(git branch 2> /dev/null | grep -e '\* ' | sed 's/^..\(.*\)/ (\1)/')]\$ "

.