forked from nvie/git-toolbelt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-shatter-by-file
executable file
·39 lines (32 loc) · 979 Bytes
/
git-shatter-by-file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/sh
set -e
locally_changes_files () {
# New files
git status --porcelain | grep -Ee '^\?' | cut -c4-
# Changes/deleted files
git diff --name-only --relative
}
main () {
# Ensure we have a clean working tree
git is-clean -v
ORIG_SHA="$(git sha HEAD)"
echo "Original commit is: $ORIG_SHA"
LAST_COMMIT_MSG="$(git log --pretty='%s' -1)"
git delouse
locally_changes_files | while read f; do
git add "$f"
git commit --no-verify -C "$ORIG_SHA"
git commit --amend --no-verify -m "$LAST_COMMIT_MSG @ $f"
done
# Sanity check
if ! git diff --exit-code "$ORIG_SHA" "$(git sha HEAD)"; then
echo "Warning! There were differences found between the current state and the" >&2
echo "original commit. You may want to revert back to the original commit:" >&2
echo "" >&2
echo " git reset --hard $ORIG_SHA" >&2
echo "" >&2
else
echo "Success! Original commit was: $ORIG_SHA"
fi
}
( cd "$(git root)" && main "$@" )