Git

From Attie's Wiki
(Difference between revisions)
Jump to: navigation, search
m
m
Line 12: Line 12:
 
|-
 
|-
 
| git push || pushes local revisions to the original path
 
| git push || pushes local revisions to the original path
 +
|-
 +
| git commit || commits to the LOCAL repository
 +
|-
 +
| git status || status since last commit
 
|-
 
|-
 
| git tag || lists the avaliable tags
 
| git tag || lists the avaliable tags
Line 21: Line 25:
 
| git fetch ''<remote-repo>'' ''<remote-branch>'':''<local-branch>'' || fetches the remote branch
 
| git fetch ''<remote-repo>'' ''<remote-branch>'':''<local-branch>'' || fetches the remote branch
 
|}
 
|}
 +
 +
==.gitconfig==
 +
<source lang="ini">
 +
[user]
 +
name = "Attie Grande"
 +
email = "attie@attie.co.uk"
 +
 +
[alias]
 +
st = status
 +
ci = commit -v
 +
</source>
  
 
==Getting the first tag that contains a file==
 
==Getting the first tag that contains a file==

Revision as of 14:27, 12 October 2011

My git cheat sheet! See my svn cheat sheet

This might also be useful: http://git.or.cz/course/svn.html#branch

command description
git clone <path> retrieves the entire git repository to your local disk
git pull pulls any new revisions from the original path
git push pushes local revisions to the original path
git commit commits to the LOCAL repository
git status status since last commit
git tag lists the avaliable tags
git checkout <branch/tag> changes the working copy to the tag specified
git reset --hard reverts all changes, to the currently checked out tag
git fetch <remote-repo> <remote-branch>:<local-branch> fetches the remote branch

.gitconfig

[user]
name = "Attie Grande"
email = "attie@attie.co.uk"
 
[alias]
st = status
ci = commit -v

Getting the first tag that contains a file

Tig?

#!/usr/local/bin/bash
if [ "$1" == "" ]; then
        echo "usage: $0 <filename>"
        exit 1
fi
 
if [ ! -e $1 ]; then
        echo "$0: File does not exist ($1)"
        exit 1
fi
 
echo -en "Finding first commit..."
COMMIT=`git log --pretty=oneline "$1" | tail -n 1 | cut -d " " -f 1`
if [ "$COMMIT" == "" ]; then
        echo "$0: Error while retrieving commits for file \"$1\""
        exit 1
fi
 
echo -en "\rFinding tags containing commit $COMMIT..."
git tag -l --contains "$COMMIT" > /tmp/tag_contains
if [ "$?" != "0" ]; then
        echo "$0: Error while retrieving tags containing commit \"$COMMIT\""
        exit 1
fi
 
echo -en "\rFinding first tag that contains $COMMIT..."
git for-each-ref --sort='-*authordate' --format='%(tag)' refs/tags/ |
while read a; do
        if [ "$a" == "" ]; then
                continue
        fi
        grep "$a" /tmp/tag_contains > /dev/null
        if [ "$?" == "0" ]; then
                LAST=$a
        else
                echo "$LAST" > /tmp/tag_first
                break
        fi
done
TAG=`cat /tmp/tag_first`
rm /tmp/tag_contains /tmp/tag_first
 
echo -en "\rFinding tag information..."
INFO=`git show "$TAG" | head -n 3 | tail -n 2`
if [ "$INFO" == "" ]; then
        echo "$0: Error retrieving info for tag \"TAG\" (maybe it isn't annotated?)"
        exit 1
fi
 
echo -en "\r\0033[K"
echo -e "File:\t\t$1"
echo -e "First tag:\t$TAG"
echo "$INFO" | sed -re 's/^(.+):[ ]+(.+)$/\1:\t\t\2/'
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox