Git notes - andreydiveev/wiki GitHub Wiki

Reset all uncommited changes:

git checkout -- .

Remove all untracked files and directories:

git clean -fd

Create patch:

git diff > my-changes.patch

Apply patch:

git apply my-changes.patch

Revert patch:

git apply -R my-changes.patch

Disable pager:

git --no-pager <subcommand> <options>

Graph:

git log --graph --decorate --oneline

Add submodule:

git submodule add -b master <remote_url> <destination_folder>

Install submodules:

git submodule init &&
git submodule update --recursive -f --checkout &&
git pull && git submodule foreach "git checkout master && git pull" &&
git submodule foreach --recursive git pull

Git delete tag:

#remote
git push origin :refs/tags/1.0.0

#local
git tag -d 1.0.0

Git clone mirror

# git clone --mirror [email protected]:myusername/myrepo.git

Git pre-commit hook:

#!/bin/sh
# Redirect output to stderr.
exec 1>&2
# enable user input
exec < /dev/tty

FAIL=0
FILE=""

# stolen from template file
if git rev-parse --verify HEAD 1> /dev/null 2>&1;
then
    against=HEAD
else
    # Initial commit: diff against an empty tree object
    against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi

# this is the magic: 
# retrieve all files in staging area that are added, modified or renamed
# but no deletions etc
FILES=$(git diff-index --name-only --cached --relative=migrations/ --diff-filter=ACMR $against -- )

for file in $FILES; do
    bugs=$(cat "migrations/"$file | grep -n "tbl_")
    for bugline in $bugs; do
        echo "[Reflected] $file\n$bugline\n";
        FAIL=1
    done
done

exit $FAIL

Git pre-receive hook:

#!/bin/sh

TMP_DIR=$(mktemp -d --tmpdir proto-pre-receive-hook.XXXXXXXX)
mkdir "$TMP_DIR/source"

ERRORS=""
FAIL=0

FILE=""

while read oldrev newrev ref;
do
    list=$(git diff-tree --name-only -r $oldrev..$newrev | grep -e '.php' -e '.phtml')
    for file in ${list}; do

        FILE="$TMP_DIR/source/$file"

        echo $FILE

        mkdir -p $(dirname $FILE)
        git show ${newrev}:${file} > $FILE

        cat $FILE | grep -n "tbl_" | while read -r line;do
            echo "\n[Reflected]\n"$FILE"\n"$line;
            FAIL=1
        done

    done
done


rm -rf $TMP_DIR

echo "$ERRORS"

exit $FAIL

Git notes:

git remote add origin [email protected]:andreydiveev/meet2.me.git


Git: delete last commit

# git reset --soft HEAD~1


Get serve

$ sudo adduser git
$ su git
$ cd
$ mkdir .ssh && chmod 700 .ssh
$ touch .ssh/authorized_keys && chmod 600 .ssh/authorized_keys

$ cat /etc/shells   # see if `git-shell` is already in there.  If not...
$ which git-shell   # make sure git-shell is installed on your system.
$ sudo mcedit /etc/shells  # and add the path to git-shell from last command
$ chsh git

$ git remote add origin git@gitserver:/opt/git/project.git

Git stash

git stash list
git stash clear
git stash drop
git stash drop stash@{0} 
⚠️ **GitHub.com Fallback** ⚠️