#!/bin/sh
#
# Git pre-commit hook that prevents really broken Drupal from code being committed.
#
# Created by Dave Hall http://davehall.com.au
#
# Fetch the list of files that have changed.
FILES="$(git diff --staged --name-only HEAD --diff-filter=ACMRTUXB)"
echo "Running PHP lint check" >&2
LINT_FAIL=0
for filename in $FILES; do
if ! php -l $filename; then
LINT_FAIL=1
fi
done;
# There is no point in running PHP Code Sniffer on broken files.
if [ $LINT_FAIL -gt 0 ]; then
exit 1
fi
echo "Running PHP Code Sniffer Checks" >&2
echo $FILES | xargs phpcs --standard=Drupal
git checkout staging
// Merge content from develop to staging ( all conflicts are resolved auto, and merge all commit in one commit.
git merge --squash -X theirs develop
// Delete config files from staging
rm -rf ../onisep/config/*.*
// Replace directory from develop.
cp -R config ../onisep
// Delete module from staging
rm -rf ../onisep/web/modules/custom/kangae/
// Replace directory from develop.
cp -R web/modules/custom/ ../onisep/web/modules
// Delete theme from staging
rm -rf ../onisep/web/themes/custom/onisep
// Replace directory from develop.
cp -R web/themes/custom/ ../onisep/web/themes
cp composer.lock ../onisep/composer.lock
$ git log --oneline --decorate
xxxxxx3 (HEAD, feature-branch) third commit
xxxxxx2 second commit
xxxxxx1 first commit
xxxxxx0 (master) starting point
If I want to fix something introduced in the second commit I can simply do :
$ git add .
$ git commit --fixup xxxxxx2
$ git log --oneline --decorate
xxxxxx4 (HEAD, feature-branch) fixup! second commit
xxxxxx3 third commit
xxxxxx2 second commit
xxxxxx1 first commit
xxxxxx0 (master) starting point
Notice the fixup! prefix of the commit message ? Now git can use this information to automatically rebase your changes :
$ git rebase --interactive --autosquash master
$ git rebase --interactive --autosquash master
This will open an interactive rebase editor session like you are accustomed to, but your fixup commit will be automatically placed correctly in the list with the correct action :
pick xxxxxx1 first commit
pick xxxxxx2 second commit
fixup xxxxxx4 fixup! second commit
pick xxxxxx3 third commit
Usually, it’s now only a matter of accepting the rebase as is and tada !
If you want to aleays autosquash you can simply add it to your config :
git config --global rebase.autosquash true
I also defined some aliases to help :
fix = commit --fixup HEAD~1 # fixup the last commmit
fixup = commit --fixup # fixup a commit in the history (need a revision)
squash = commit --squash # squash a commit in the history (need a revision)
ri = rebase --interactive # interactive rebase
fix = commit --fixup HEAD~1 # fixup the last commmit
fixup = commit --fixup # fixup a commit in the history (need a revision)
squash = commit --squash # squash a commit in the history (need a revision)
ri = rebase --interactive # interactive rebase
git status -s | grep -E '^ D' | cut -d ' ' -f3 | xargs git add --all
// Get last tag in current branch.
git describe --tags --abbrev=0