Skip to content

Instantly share code, notes, and snippets.

@kunathj
Last active August 17, 2020 10:26
Show Gist options
  • Save kunathj/1f58d236e5a54237e7ac34c7ef0fc22e to your computer and use it in GitHub Desktop.
Save kunathj/1f58d236e5a54237e7ac34c7ef0fc22e to your computer and use it in GitHub Desktop.
Git
# Show all files in the history.
git log --pretty=format: --name-only --diff-filter=A | sort -u
# Remove some files (F).
git filter-branch --tree-filter 'rm -f F' HEAD
# If you want to iterate this, it is necessary to remove the
# .git/refs/original folder.
rm -r .git/refs/original/
# Now we can push the repo back up to the origin.
# Clearly it is necessary that we are the only ones working with the repo
# right now.
# How to change the git history when my commits are shown as commits from multiple people.
# ! Reverts history. Only use this when working on a project alone.
# https://help.github.com/en/github/using-git/changing-author-info
REPO_NAME="ZH"
git clone --bare git@github.com/kunathj/$REPO_NAME.git
cd $REPO_NAME.git
# The working horse.
git filter-branch --env-filter '
CORRECT_NAME="Jonas Kunath"
CORRECT_EMAIL="jonas.kunath@gmx.de"
for OLD_NAME in "kunathj" "vscode Jonas" "Jonas Kunath"; do
if [ "$GIT_COMMITTER_NAME" = "$OLD_NAME" ]; then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
if [ "$GIT_AUTHOR_NAME" = "$OLD_NAME" ]; then
export GIT_AUTHOR_NAME="$CORRECT_NAME"
export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
fi
done
' --tag-name-filter cat -- --branches --tags
git push --force --tags origin 'refs/heads/*'
cd ..
rm -rf $REPO_NAME.git
# List the authors contibuting to a repo
git shortlog -s
# Incorporte remote chanegs to the repo.
git fetch origin
git reset --hard origin/master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment