git

git is a (distributed) version control system.

installation

aptitude install git-core git-doc

configuration

git config --global user.name "John Doe"
git config --global user.email johndoe@example.com

git config --global core.editor joe

# see whats configured:
git config --list

howto git

Initializing a repos in an existing directory:

git init

Exclude *~ files: edit $GIT_DIR/info/exclude

repodir/info/exclude
# git-ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
*~
*_disabled
*.disabled
*.bkup
*-dist

Ignore files when running git status:

repodir/.gitignore
# Lines that start with '#' are comments.
.gitignore
*~
*_disabled
*.disabled
*.bkup
*-dist

Add all files in current directory to git staging:

git add .

See status:

git status

See diffs:

# only changes that are still unstaged:
git diff
 
# already staged that will go into your next commit:
git diff --cached

Commit:

git commit
# or
git commit -m "log message"

Remove a file:

git rm file
 
# glob:
git rm \*~
 
# remove it from the staging area:
git rm --cached file

Move or rename a file:

git mv file_from file_to

Undo changes to a file:

git checkout HEAD file.sh

View logs:

git log
git log --stat
git log --pretty=format:"%h - %an, %ar : %s"
git log --pretty=format:"%h %s" --graph
git log --since=3.weeks

List available tags:

git tag

List tags in alphabetical order:

git tag -l v0.1.*

Create annotated tag (stored as full objects in git):

# create the tag
git tag -a v0.0.1 -m '1st working version'
 
#show tag
git show v0.0.1

Create lightweigth tag (pointer to a specific commit):

git tag v.0.0.2

gitweb

Install the gitweb webfrontend
A nice gitweb theme can be found here: git://github.com/kogakure/gitweb-theme.git

aptitude install gitweb
mkdir -p /var/www/git/cgi-bin
ln -s /usr/lib/cgi-bin/gitweb.cgi /var/www/git/cgi-bin
cp -a /usr/share/gitweb/* /var/www/git

Configure apache:

a2enmod rewrite
cat > /etc/apache2/sites-available/git <<EOM
<VirtualHost *:80>
    ServerName git.example.com
    DocumentRoot /var/www/git
    SetEnv      GITWEB_CONFIG   /etc/gitweb.conf
    RewriteEngine on
    # make the front page an internal rewrite to the gitweb script
    RewriteRule ^/$  /cgi-bin/gitweb.cgi
    # make access for "dumb clients" work
    RewriteRule ^/(.*\.git/(?!/?(HEAD|info|objects|refs)).*)?$ /cgi-bin/gitweb.cgi%{REQUEST_URI}  [L,PT]
 
  <Directory /var/www/git/cgi-bin>
    Options +ExecCGI -Indexes
    SetHandler cgi-script
  </Directory>
 
</VirtualHost>
EOM
 
a2ensite git
/etc/init.d/apache2 restart

Add your project to gitweb

ln -s /path/to/project/.git /var/cache/git/project

from svn to git

Converting an subversion repository to git.

aptitude install git-svn
 
cd ~
mkdir git
cd git
echo "user = Joe User <j.user@example.com>" > authors.txt
git svn clone --no-metadata --username=user -A ./authors.txt https://svn.example.lan/svn/repos
 
# if there are tags, branches etc.
# git svn clone --no-metadata --username=user -t tags -b branches -T trunk -A ./authors.txt https://svn.example.lan/svn/repos
howto/git.txt · Last modified: 2011/11/24 13:05 by tb
CC Attribution-Noncommercial-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0