-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
109 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,53 @@ | ||
#!/bin/sh | ||
#!/usr/bin/env bash | ||
|
||
destinationRef=$1 | ||
originRef=$2 | ||
pathspec=$3 | ||
test -z "$destinationRef" && echo "ERROR: Please provide the destination reference." 1>&2 && exit 1 | ||
test -z "$originRef" && echo "ERROR: Please provide the origin reference." 1>&2 && exit 1 | ||
test -z "$pathspec" && echo "ERROR: Please provide the paths to be extracted." 1>&2 && exit 1 | ||
set -Eeuo pipefail | ||
|
||
git checkout "$originRef" | ||
usage() { | ||
cat <<EOF | ||
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-b] <against> <new-branch> <pathspec> (<base>) | ||
<against> The branch you will merge changes into | ||
<new-branch> The branch you want to create | ||
<pathspec> the path you wish to split ("some/path/*") | ||
<base> (optional) The tool will attempt to auto-detect the common ancestor | ||
between your branch and the against target. If your branch histories | ||
are complicated you can manually provide the original ancestor commit. | ||
git checkout -b "$originRef-extracted" | ||
Break a big feature branch into a smaller specific branch with the changes from | ||
one specific folder. Also, preserve your commit history. | ||
git filter-branch --force --prune-empty --index-filter \ | ||
"git ls-files | grep -Ev $pathspec | xargs git rm --cached" "$(git merge-base "$destinationRef" "$originRef")..HEAD" | ||
EOF | ||
exit | ||
} | ||
|
||
git checkout "$destinationRef" | ||
git merge "$originRef-extracted" --no-edit --allow-unrelated-histories | ||
AGAINST=${1:-} | ||
NEW_BRANCH=${2:-} | ||
PATHSPEC=${3:-} | ||
if [ "$#" -lt 3 ]; then | ||
usage | ||
fi | ||
|
||
BASE=${4:-$(git merge-base "$AGAINST" HEAD)} | ||
|
||
git checkout -b "$NEW_BRANCH" || exit | ||
|
||
FILTER_BRANCH_SQUELCH_WARNING=1 git filter-branch --force --prune-empty --index-filter \ | ||
"git ls-files | grep -Ev $PATHSPEC | xargs git rm --cached" "$BASE..HEAD" | ||
|
||
|
||
cat <<EOF | ||
-------------------------------------------------------------------------------- | ||
Your new branch is created and checked out. | ||
You should be able to merge the branch as you normally would. In some | ||
situations git may not permit merges due to the "history" being "unrelated" | ||
(for example, if you introduce a new folder in your branch it has no common | ||
ancestor in the branch you wish to merge into. In this situation you must tell | ||
git to merge a branch with unrelated history: the unrelated history: | ||
git checkout $AGAINST | ||
git merge $NEW_BRANCH --no-edit --allow-unrelated-histories | ||
A regular git merge is usually all you need. You only need to do this if it | ||
complains. | ||
-------------------------------------------------------------------------------- | ||
EOF |
This file was deleted.
Oops, something went wrong.