[git] Add git-merge-ff-only
This commit is contained in:
parent
bca8250c5a
commit
6c5525185c
18
git/README
18
git/README
|
@ -28,3 +28,21 @@ in a directory in the PATH (for instance /usr/local/bin) and add an
|
|||
alias:
|
||||
|
||||
git config --global alias.cherry-move "\!sh -c 'git-cherry-move'"
|
||||
|
||||
|
||||
# git-merge-ff-only #
|
||||
|
||||
git-merge-ff-only main_branch topic_branch is the equivalent of the
|
||||
following commands:
|
||||
|
||||
git checkout main_branch && git merge --ff-only topic_branch
|
||||
|
||||
except that main_branch is not checked out. The reference is updated
|
||||
directly (if possible), and HEAD stays on whatever branch was checked
|
||||
out before running the command.
|
||||
|
||||
To activate the git merge-ff-only command, put the git-merge-ff-only
|
||||
script in a directory in the PATH (for instance /usr/local/bin) and
|
||||
add an alias:
|
||||
|
||||
git config --global alias.merge-ff-only "\!sh -c 'git-merge-ff-only'"
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# git-merge-ff-only, Copyright © 2012 Matteo Cypriani
|
||||
#
|
||||
# This program is free software. It comes without any warranty, to
|
||||
# the extent permitted by applicable law. You can redistribute it
|
||||
# and/or modify it under the terms of the Do What The Fuck You Want
|
||||
# To Public License, Version 2, as published by Sam Hocevar. See
|
||||
# http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
#
|
||||
# This script fast-forwards a branch (main_branch) to another branch
|
||||
# (topic_branch), if possible. It is equivalent to git checkout
|
||||
# main_branch && git merge --ff-only topic_branch, but the effort of
|
||||
# checking out the main branch is saved (git branch -f is used to update
|
||||
# the reference directly).
|
||||
|
||||
set -e
|
||||
|
||||
if [ $# -ne 2 ] ; then
|
||||
echo "Usage: $0 <main_branch> <topic_branch>"
|
||||
echo "<main_branch> will be fast-forwarded to <topic_branch> if possible."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
MAIN_BRANCH="$1"
|
||||
TOPIC_BRANCH="$2"
|
||||
|
||||
echo "Trying to merge $TOPIC_BRANCH into $MAIN_BRANCH..."
|
||||
|
||||
DIFF="$(git rev-list "$TOPIC_BRANCH".."$MAIN_BRANCH")"
|
||||
if [ -z "$DIFF" ] ; then
|
||||
echo "$TOPIC_BRANCH contains all the commits of $MAIN_BRANCH."
|
||||
echo "Fast-forwarding $MAIN_BRANCH to $TOPIC_BRANCH."
|
||||
git branch -f "$MAIN_BRANCH" "$TOPIC_BRANCH"
|
||||
else
|
||||
echo "$TOPIC_BRANCH does not contain all the commits of $MAIN_BRANCH."
|
||||
echo "Fast-forward impossible, aborting."
|
||||
fi
|
Loading…
Reference in New Issue