Difference between revisions of "Git"

From Wiki
Jump to: navigation, search
Line 1: Line 1:
 +
== Git Notes ==
 
Undo bad merge:
 
Undo bad merge:
  
Line 12: Line 13:
  
 
See also: http://stackoverflow.com/questions/1407638/git-merge-removing-files-i-want-to-keep
 
See also: http://stackoverflow.com/questions/1407638/git-merge-removing-files-i-want-to-keep
 +
 +
== 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.
 +
 +
<pre>
 +
<VirtualHost *:80>
 +
    ServerAdmin ops-team@example.com
 +
    DocumentRoot /var/www/html
 +
    ServerName server1.example.com
 +
</VirtualHost>
 +
</pre>
 +
 +
Next edit the /etc/httpd/conf.d/git.conf config file for gitweb. 
 +
 +
<pre>
 +
<VirtualHost *:80>
 +
ServerName git.example.com
 +
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 192.168.0.0/24
 +
</Directory>
 +
 +
# 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))$" \
 +
          /var/www/gitweb/git-http-backend/$1
 +
</VirtualHost>
 +
</pre>
 +
 +
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.
 +
 +
<pre>
 +
# path to git projects (.git)
 +
$projectroot = "/home/git/repositories";
 +
 +
#uncomment this to display URLs for cloning
 +
#@git_base_url_list = ("git://git.example.com", "http://git.example.com");
 +
 +
# directory to use for temp files
 +
$git_temp = "/tmp";
 +
 +
$site_name = "git.example.com";
 +
 +
# 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];
 +
</pre>

Revision as of 14:04, 20 January 2016

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: http://stackoverflow.com/questions/1407638/git-merge-removing-files-i-want-to-keep

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>
    ServerAdmin ops-team@example.com
    DocumentRoot /var/www/html
    ServerName server1.example.com
</VirtualHost>

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

<VirtualHost *:80>
ServerName git.example.com
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 192.168.0.0/24
</Directory>

# 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))$" \
          /var/www/gitweb/git-http-backend/$1
</VirtualHost>

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://git.example.com", "http://git.example.com");

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

$site_name = "git.example.com";

# 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];