Skip to content

Instantly share code, notes, and snippets.

@KubaO
Last active August 24, 2021 16:00
Show Gist options
  • Save KubaO/3fed128f54ec4eee413479aca137d8e1 to your computer and use it in GitHub Desktop.
Save KubaO/3fed128f54ec4eee413479aca137d8e1 to your computer and use it in GitHub Desktop.
Remove all replace refs in git
# /bin/bash
# This removes all replace refs in the current repo, after logging them.
set -e
cmd=$(basename "$0")
logfile="~/.${cmd}.log.txt"
tmpfile=$(mktemp "${TMPDIR}/.${cmd}")
origin=$(git config --get remote.origin.url)
echo "# $(date) BEGIN ${origin}" >> "${logfile}"
git replace -l >> "${tmpfile}"
cat "${tmpfile}" >> "${logfile}"
echo "# $(date) END" >> "${logfile}"
xargs --no-run-if-empty --arg-file="${tmpfile}" --max-args=25 git replace -d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment