From Wiki
Revision as of 13:43, 15 February 2016 by Admin (Talk | contribs)

Jump to: navigation, search

Git Notes

Undo bad merge

git clone <repo>
git checkout <commit_id>
git merge --no-commit master
git revert <commit_id>
git add .
git commit
git push

See also:

Set up initial repo for push

You will need to set up an empty directory and then initialize it to store git data.

mkdir newproject
cd newproject
git init

Now push from your *source* repo.

git push master

Gitweb Installation

git includes a cgi script which can be used to browse git repositories. To set this up first install the packages:

yum -y install gitweb httpd

Edit the apache config file to enable name based virtual hosts. Uncomment the line that says "NameVirtualHost *:80".

Set up a default virtual host. For example, add these lines to httpd.conf.

<VirtualHost *:80>
    DocumentRoot /var/www/html

Next edit the /etc/httpd/conf.d/git.conf config file for gitweb.

<VirtualHost *:80>
SuexecUserGroup git git
DocumentRoot /var/www/gitweb

SetEnv GITWEB_CONFIG  /etc/gitweb.conf
SetEnv GIT_PROJECT_ROOT /home/git/repositories
ScriptAlias /git/ /var/www/gitweb/gitweb.cgi/

# Logfiles
ErrorLog  /var/log/httpd/gitweb.error.log
CustomLog /var/log/httpd/gitweb.access.log combined

<Directory /var/www/gitweb>
    Options +ExecCGI +FollowSymLinks
    AddHandler cgi-script .cgi
    DirectoryIndex gitweb.cgi

    # Pretty gitweb URLs
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^.* /gitweb.cgi/$0 [L,PT]

    Order Deny,Allow
    Deny from all
    Allow from

# Enable git clone over HTTP - does not work
ScriptAliasMatch \
          "(?x)^/(.*/(HEAD | \
          info/refs | \
          objects/(info/[^/]+ | \
          [0-9a-f]{2}/[0-9a-f]{38} | \
          pack/pack-[0-9a-f]{40}\.(pack|idx)) | \
          git-(upload|receive)-pack))$" \

Since we are using suexec the gitweb files must be copied into the default document root.

rsync -avHl /usr/share/gitweb/ /var/www/gitweb/
chown -R git:git /var/www/gitweb/

Restart apache.

Edit /etc/gitweb.conf to customize gitweb for your environment.

# path to git projects (.git)
$projectroot = "/home/git/repositories";

#uncomment this to display URLs for cloning
#@git_base_url_list = ("git://", "");

# directory to use for temp files
$git_temp = "/tmp";

$site_name = "";

# require export flag
$export_ok = "git-daemon-export-ok";
$strict_export = 1;

# target of the home link on top of all pages
#$home_link = $my_uri || "/";

# html text to include at home page
#$home_text = "indextext.html";

# file with project list; by default, simply scan the projectroot dir.
#$projects_list = $projectroot;

# stylesheet to use
#$stylesheet = "gitweb.css";

# javascript code for gitweb
#$javascript = "gitweb.js";

# logo to use
#$logo = "git-logo.png";

# the 'favicon'
#$favicon = "git-favicon.png";

# enable git blame
$feature{'blame'}{'default'} = [1];

# enable pickaxe search
$feature{'pickaxe'}{'default'} = [1];

# enable snapshot downloads
$feature{'snapshot'}{'default'} = ['zip', 'tgz'];

# enable syntax highlighting
$feature{'highlight'}{'default'} = [1];

# enable pretty URLs
$feature{'pathinfo'}{'default'} = [1];