Last active
May 1, 2020 17:16
-
-
Save EricCousineau-TRI/739a3cc7483d26b047fe19d02fa4b38e to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# This allows for a "simple squash". This will be *greatly* simplified once | |
# newer version of Git (with `git restore`) are more widly available. | |
# Motivation behind this is to make a simple, commit-info-losing "squash" that | |
# helps Reviewable not make multiple revs: | |
# https://github.com/Reviewable/Reviewable/issues/592 | |
# To run in shell, copy everything, including parentheses. | |
( set -eux; | |
if [[ -n "$(git status --porcelain)" ]]; then | |
echo "You have changes in your tree (staged / unstaged). Stash them before using this." | |
exit 1 | |
fi | |
# You're on your feature branch. | |
work_rev=$(git rev-parse --short HEAD) | |
set +x | |
echo | |
echo "If you encounter issues, be sure to reset:" | |
echo | |
echo " git reset --hard ${work_rev}" | |
echo | |
echo "Or use 'git reflog'" | |
echo | |
set -x | |
master_rev=$(git merge-base upstream/master ${work_rev}) | |
# Reset to ref and worktree to current upstream master. | |
git reset --hard ${master_rev} | |
# Reverse so that we can show files that should be deleted / renamed. | |
# (For now, we will delete everything.) | |
files_from_prev=$(git diff --name-only ${work_rev}..${master_rev}) | |
rm -f ${files_from_prev} | |
# Now reset all files to previous commit. | |
git checkout ${work_rev} -- :/ | |
# Stage them for easy diff'ing. | |
git add -A :/ | |
# Ensure we have zero differences now. | |
git diff ${work_rev} | |
# Now commit. | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment